-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Description
Describe the bug
Timezone plugin is not taking into consideration the default timezone when parsing a date.
Expected behavior
Extend dayJs with plugins and set default timezone as
dayjs.extend(customParseFormat);
dayjs.extend(utc);
dayjs.extend(timezone);
dayjs.tz.setDefault('UTC')
Try to read a date in the zone using -
dayjs.tz('01 Aug 2025').format()
Actual output: '2025-07-31T18:30:00+00:00'
Expected output: '2025-08-01T00:00:00+00:00'
I tried some other combinations like
dayjs.tz('01 Aug 2025', undefined, 'UTC').format()
// Gives incorrect output '2025-07-31T18:30:00+00:00'
dayjs.tz('01 Aug 2025', 'DD MMM YYYY', 'UTC').format()
// Gives correct output - '2025-08-01T00:00:00.000Z'
But I have already set the default timezone and don't want to pass the same every time parsing a string. So I thought maybe the issue is that format needs to be passed but
dayjs.tz('01 Aug 2025', 'DD MMM YYYY').format()
or
dayjs.tz('01 Aug 2025', 'DD MMM YYYY', undefined).format()
throws error
Uncaught RangeError: Invalid time zone specified: DD MMM YYYY
at new DateTimeFormat (<anonymous>)
at timezone.js:1:485
So It seems impossible to just pass the format of the date being parsed and use the default timezone.
Information
- Day.js Version 1.11
- OS: MacOS
- Browser Chrome 133
- Time zone: GMT+05:30 IST (Indian Standard Time)]