@@ -26,7 +26,7 @@ import {
26
26
utcSecond ,
27
27
} from 'd3-time'
28
28
29
- import { timeFormat } from 'd3-time-format'
29
+ import { timeFormat , utcFormat } from 'd3-time-format'
30
30
31
31
import {
32
32
Axis ,
@@ -206,35 +206,42 @@ function buildTimeAxis<TDatum>(
206
206
}
207
207
}
208
208
209
+ const resolvedTimeFormat = isLocal ? timeFormat : utcFormat
209
210
const trimFormat = ( str : string ) => str . trim ( ) . replace ( / ( , $ | ^ , ) / , '' )
210
211
211
212
const contextFormat = ( format : string , date : Date ) => {
212
213
if ( units . second ( date ) < date ) {
213
214
// milliseconds - Do not remove any context
214
- return timeFormat ( format ) ( date )
215
+ return resolvedTimeFormat ( format ) ( date )
215
216
}
216
217
if ( units . minute ( date ) < date ) {
217
218
// seconds - remove potential milliseconds
218
- return timeFormat ( trimFormat ( format . replace ( / \. % L .* ?( \s | $ ) / , '' ) ) ) ( date )
219
+ return resolvedTimeFormat (
220
+ trimFormat ( format . replace ( / \. % L .* ?( \s | $ ) / , '' ) )
221
+ ) ( date )
219
222
}
220
223
if ( units . hour ( date ) < date ) {
221
224
// 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
+ )
223
228
}
224
229
if ( units . day ( date ) < date ) {
225
230
// 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
+ )
227
234
}
228
235
if ( units . month ( date ) < date ) {
229
236
// days - remove potential hours, minutes, seconds and milliseconds
230
- return timeFormat ( trimFormat ( format . replace ( / % - I .* / , '' ) ) ) ( date )
237
+ return resolvedTimeFormat ( trimFormat ( format . replace ( / % - I .* / , '' ) ) ) ( date )
231
238
}
232
239
if ( units . year ( date ) < date ) {
233
240
// 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 )
235
242
}
236
243
// years
237
- return timeFormat ( '%Y' ) ( date )
244
+ return resolvedTimeFormat ( '%Y' ) ( date )
238
245
}
239
246
240
247
let shouldNice = options . shouldNice
0 commit comments