Chrome 67 - 72: Time incorrectly parsed
Semigradsky opened this issue · comments
Dmitry Semigradsky commented
For Chrome 67 currently 18:00
is parsed as 6:00
.
See
date-fns-tz/src/_lib/tzTokenizeDate/index.js
Lines 53 to 88 in a92e0ad
We have comment here:
New browsers use
hourCycle
, IE and Chrome <73 does not support it and useshour12
But not hourCycle
tested and in code hour12: false
used if the hour cycle is supported. It looks like checking should be changed and if
branches should be swapped.
Dmitry Semigradsky commented
Example (in Chrome 67):
const timeZone = 'Europe/Riga'
const date = new Date('2023-04-04T18:00:00.000Z')
new Intl.DateTimeFormat('en-US', {
hourCycle: 'h23',
timeZone: timeZone,
year: 'numeric',
month: 'numeric',
day: '2-digit',
hour: '2-digit',
minute: '2-digit',
second: '2-digit',
}).formatToParts(date)
/*
0: {type: "month", value: "4"}
1: {type: "literal", value: "/"}
2: {type: "day", value: "04"}
3: {type: "literal", value: "/"}
4: {type: "year", value: "2023"}
5: {type: "literal", value: ", "}
6: {type: "hour", value: "9"} // <- hour will be parsed as `09`
7: {type: "literal", value: ":"}
8: {type: "minute", value: "00"}
9: {type: "literal", value: ":"}
10: {type: "second", value: "00"}
11: {type: "literal", value: " "}
12: {type: "dayperiod", value: "PM"}
*/
new Intl.DateTimeFormat('en-US', {
hour12: false,
timeZone: timeZone,
year: 'numeric',
month: 'numeric',
day: '2-digit',
hour: '2-digit',
minute: '2-digit',
second: '2-digit',
}).formatToParts(date)
/*
0: {type: "month", value: "4"}
1: {type: "literal", value: "/"}
2: {type: "day", value: "04"}
3: {type: "literal", value: "/"}
4: {type: "year", value: "2023"}
5: {type: "literal", value: ", "}
6: {type: "hour", value: "21"} // <- hour is okay
7: {type: "literal", value: ":"}
8: {type: "minute", value: "00"}
9: {type: "literal", value: ":"}
10: {type: "second", value: "00"}
*/
Dmitry Semigradsky commented
@marnusw Could you please take a look?
Dmitry Semigradsky commented
UPD:
Affected browsers: at least Chrome 67 - 72
pimothyxd commented
Any updates on this?