Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot strict parse date with timezone (ZZ) #2797

Open
ledenis opened this issue Dec 26, 2024 · 0 comments
Open

Cannot strict parse date with timezone (ZZ) #2797

ledenis opened this issue Dec 26, 2024 · 0 comments

Comments

@ledenis
Copy link

ledenis commented Dec 26, 2024

Describe the bug

Parsing a date in strict mode (with customParseFormat plugin) with timezone (ZZ / +0600) 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant