Date parsing with tz does not respect the default set timezone
- Dominant language
- JavaScript
- Stars
- 48.7k
- Forks
- 2.5k
- PR merge metrics
- No merged PRs in 30d
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 ()
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)]
Contributor guide
Research direction
Start by reproducing the documented case with the customParseFormat, utc, and timezone plugins, including the default UTC setting. Inspect timezone.js and the plugin parsing path to determine why the default zone is ignored, then verify that dayjs.tz('01 Aug 2025').format() produces 2025-08-01T00:00:00+00:00 without requiring the timezone or format on every call.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100