You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I encountered an issue with the TZDate class when handling dates before the implementation of the GMT system in 1883. The TZDate class appears to only consider the hour and minute of the timezone, but not the seconds, leading to inconsistencies.
Steps to Reproduce:
Create a TZDate object with a date before 1883.
Compare the output of ISOString, toString, and getDate methods with the same methods of a pure JavaScript Date object.
Example Code:
import { TZDate, TZDateMini } from '@date-fns/tz';
import { lastDayOfMonth, startOfMonth } from 'date-fns';
const tzDate = new TZDate('1860-01-01T00:00:57.000Z', 'America/Los_Angeles');
const jsDate = new Date('1860-01-01T00:00:57.000Z');
console.log('TZDate');
console.log('ISOString:', tzDate.toISOString());
console.log('toString:', tzDate.toString());
console.log('getDate:', tzDate.getDate());
console.log('pure javascript date');
console.log('ISOString:', jsDate.toISOString());
console.log('toString:', jsDate.toString());
console.log('getDate:', jsDate.getDate());
console.log('Error in use');
console.log('Last day of month (TZDate):', lastDayOfMonth(tzDate).toString());
console.log('Last day of month (Date):', lastDayOfMonth(jsDate).toString());
Observed Output:
TZDate
ISOString: 1860-01-01T00:00:57.000-07:52
toString: Sun Jan 01 1860 00:00:57 GMT-0752 (GMT-07:52:58)
getDate: 1
pure javascript date
ISOString: 1860-01-01T07:52:57.000Z
toString: Sat Dec 31 1859 23:59:59 GMT-0752 (Pacific Standard Time)
getDate: 31
Error in use
Last day of month (TZDate): Mon Jan 30 1860 23:59:00 GMT-0752 (Pacific Standard Time)
Last day of month (Date): Sat Dec 31 1859 00:00:00 GMT-0752 (Pacific Standard Time)
Expected Output: The TZDate and pure JavaScript Date objects should produce consistent results for the same date and timezone.
Additional Information: The issue seems to stem from TZDate only considering the hour and minute of the timezone, but not the seconds. This discrepancy becomes apparent for dates before 1883, when the GMT system was implemented. The offset GMT-07:52:58 (America/Los_Angelos, GMT-08:00) causes the inconsistency.
The text was updated successfully, but these errors were encountered:
I encountered an issue with the TZDate class when handling dates before the implementation of the GMT system in 1883. The TZDate class appears to only consider the hour and minute of the timezone, but not the seconds, leading to inconsistencies.
Steps to Reproduce:
Create a TZDate object with a date before 1883.
Compare the output of ISOString, toString, and getDate methods with the same methods of a pure JavaScript Date object.
Example Code:
Observed Output:
Expected Output: The TZDate and pure JavaScript Date objects should produce consistent results for the same date and timezone.
Example
Additional Information: The issue seems to stem from TZDate only considering the hour and minute of the timezone, but not the seconds. This discrepancy becomes apparent for dates before 1883, when the GMT system was implemented. The offset GMT-07:52:58 (America/Los_Angelos, GMT-08:00) causes the inconsistency.
The text was updated successfully, but these errors were encountered: