iamkun / iamkun/dayjs

Cannot strict parse date with timezone (ZZ)

Open
#2,797 2 comments 8 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
48.7k
Forks
2.5k
PR merge metrics
No merged PRs in 30d

Description

**Describe the bug**

Parsing a date in strict mode (with `customParseFormat` plugin) with [timezone (ZZ / +0600)](https://day.js.org/docs/en/parse/string-format#:~:text=ZZ) returns a date object which is not `.isValid()`.

```
const dayjs = require("dayjs");
const customParseFormat = require("dayjs/plugin/customParseFormat");

dayjs.extend(customParseFormat);

const dateFormat = "YYYYMMDD HHmmss ZZ";

const date = dayjs("20241224 061500 +0600", dateFormat);
console.log("date.isValid()", date.isValid()); // true
console.log("isoString", date.toISOString()); // 2024-12-24T00:15:00.000Z

const dateStrict = dayjs("20241224 061500 +0600", dateFormat, true);
console.log("dateStrict.isValid()", dateStrict.isValid()); // false <---------- WRONG
console.log("isoString", dateStrict.toISOString()); // throws RangeError: Invalid time value

```

**Expected behavior**

* `dateStrict.isValid()` should return true
* `dateStrict.toISOString()` should not throw `RangeError: Invalid time value`, it should return `2024-12-24T00:15:00.000Z`

**Information**
- Day.js Version: v1.11.13
- OS: Linux Mint 20.2
- Node v20.10.0
- Time zone: Europe/Paris

Contributor guide

Open the contributing guide

Research direction

Start at the customParseFormat plugin's strict parsing path and compare it with the non-strict path using the supplied reproduction. Done means the strict example is valid and produces the expected ISO timestamp without throwing, with coverage for the ZZ timezone format.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
devtools
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.