Bug Report: Timezone Handling in Day.js Plugins
Describe the bug
When the local computer timezone is set to US/Los_Angeles, most plugin test cases fail. After the latest fixes, almost all test cases pass except for two:
test/plugin/localizedFormat.test.js
test/plugin/dayOfYear.test.js
These two are hard to fix because Day.js does not store the timezone information when parsing a string. Therefore, functions like dayOfYear and format can only operate based on the current environment's timezone. Fixing this properly would require a core feature change in Day.js to store the original string’s timezone, which would be a significant modification.
Expected behavior
All plugin test cases should pass regardless of the local system timezone, correctly handling dayOfYear and format when the input string contains a timezone offset.
Information
- Day.js Version: ALL
- OS: macOS / Windows (any OS, but tested on US/LA timezone)
- Browser: N/A (Node.js environment)
- Time zone: US/Pacific (GMT-07:00 DST, Pacific Daylight Time)
Test cases demonstrating the issue
describe('Timezone conversion format', () => {
it('converts between fixed-offset timezones correctly', () => {
expect(dayjs.tz('2025-03-09 12:00', 'Etc/GMT-5').tz('Etc/GMT+5').format())
.toBe('2025-03-09T02:00:00-05:00');
expect(dayjs.tz('2025-03-09 12:30', 'Etc/GMT-5').tz('Etc/GMT+5').format())
.toBe('2025-03-09T02:30:00-05:00');
});
it('converts from fixed-offset timezone to IANA timezone correctly', () => {
expect(dayjs('2025-03-08T21:00:00.000Z')
.tz('Etc/GMT-5')
.tz('America/Argentina/Buenos_Aires')
.format()).toBe('2025-03-08T18:00:00-03:00');
});
});
<img width="2370" height="1846" alt="Image" src="https://github.com/user-attachments/assets/6d33e4f5-afaf-4422-916a-98dba169c767" />
Bug Report: Timezone Handling in Day.js Plugins
Describe the bug
When the local computer timezone is set to US/Los_Angeles, most plugin test cases fail. After the latest fixes, almost all test cases pass except for two:
test/plugin/localizedFormat.test.jstest/plugin/dayOfYear.test.jsThese two are hard to fix because Day.js does not store the timezone information when parsing a string. Therefore, functions like
dayOfYearandformatcan only operate based on the current environment's timezone. Fixing this properly would require a core feature change in Day.js to store the original string’s timezone, which would be a significant modification.Expected behavior
All plugin test cases should pass regardless of the local system timezone, correctly handling
dayOfYearandformatwhen the input string contains a timezone offset.Information
Test cases demonstrating the issue