@@ -26,7 +26,7 @@ import {
2626 utcSecond ,
2727} from 'd3-time'
2828
29- import { timeFormat } from 'd3-time-format'
29+ import { timeFormat , utcFormat } from 'd3-time-format'
3030
3131import {
3232 Axis ,
@@ -206,35 +206,42 @@ function buildTimeAxis<TDatum>(
206206 }
207207 }
208208
209+ const resolvedTimeFormat = isLocal ? timeFormat : utcFormat
209210 const trimFormat = ( str : string ) => str . trim ( ) . replace ( / ( , $ | ^ , ) / , '' )
210211
211212 const contextFormat = ( format : string , date : Date ) => {
212213 if ( units . second ( date ) < date ) {
213214 // milliseconds - Do not remove any context
214- return timeFormat ( format ) ( date )
215+ return resolvedTimeFormat ( format ) ( date )
215216 }
216217 if ( units . minute ( date ) < date ) {
217218 // seconds - remove potential milliseconds
218- return timeFormat ( trimFormat ( format . replace ( / \. % L .* ?( \s | $ ) / , '' ) ) ) ( date )
219+ return resolvedTimeFormat (
220+ trimFormat ( format . replace ( / \. % L .* ?( \s | $ ) / , '' ) )
221+ ) ( date )
219222 }
220223 if ( units . hour ( date ) < date ) {
221224 // minutes - remove potential seconds and milliseconds
222- return timeFormat ( trimFormat ( format . replace ( / : % S .* ?( \s | $ ) / , '' ) ) ) ( date )
225+ return resolvedTimeFormat ( trimFormat ( format . replace ( / : % S .* ?( \s | $ ) / , '' ) ) ) (
226+ date
227+ )
223228 }
224229 if ( units . day ( date ) < date ) {
225230 // hours - remove potential minutes and seconds and milliseconds
226- return timeFormat ( trimFormat ( format . replace ( / : % M .* ?( \s | $ ) / , '' ) ) ) ( date )
231+ return resolvedTimeFormat ( trimFormat ( format . replace ( / : % M .* ?( \s | $ ) / , '' ) ) ) (
232+ date
233+ )
227234 }
228235 if ( units . month ( date ) < date ) {
229236 // days - remove potential hours, minutes, seconds and milliseconds
230- return timeFormat ( trimFormat ( format . replace ( / % - I .* / , '' ) ) ) ( date )
237+ return resolvedTimeFormat ( trimFormat ( format . replace ( / % - I .* / , '' ) ) ) ( date )
231238 }
232239 if ( units . year ( date ) < date ) {
233240 // months - remove potential days, hours, minutes, seconds and milliseconds
234- return timeFormat ( trimFormat ( format . replace ( / % - d .* / , '' ) ) ) ( date )
241+ return resolvedTimeFormat ( trimFormat ( format . replace ( / % - d .* / , '' ) ) ) ( date )
235242 }
236243 // years
237- return timeFormat ( '%Y' ) ( date )
244+ return resolvedTimeFormat ( '%Y' ) ( date )
238245 }
239246
240247 let shouldNice = options . shouldNice
0 commit comments