You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The text was updated successfully, but these errors were encountered:
maxkomarychev
changed the title
bug: validation of 4 digit years with YYYY is not working
bug: validation of years with arbitrary number of digits with YYYY is not working
May 15, 2024
Unable to replicate this issue in Node.js. The custom format requires the "customParseFormat" plugin - are you testing with this plugin imported too? I've written a quick test in Node:
import dayjs from "dayjs";
const format = "YYYY-MM-DD";
const strictMode = true;
const dates = [
"2024-05-30", // control - should be true for both tests
"2022-02-31",
"202-02-31",
"02-02-31",
"2-02-31",
];
console.log("Test without plugin:")
for (const date of dates) {
console.log(`Date: ${date}. Result: ${dayjs(date, format, strictMode).isValid()}`);
}
console.log("\nTest with plugin:")
import customParseFormat from "dayjs/plugin/customParseFormat.js";
dayjs.extend(customParseFormat);
for (const date of dates) {
console.log(`Date: ${date}. Result: ${dayjs(date, format, strictMode).isValid()}`);
}
Describe the bug
Validation does not work properly with the strict flag https://day.js.org/docs/en/parse/is-valid
All these dates are considered valid even though the "YYYY" is used and there are dates which have <4 digits in year:
Expected behavior
A clear and concise description of what you expected to happen.
"YYYY" must only allow 4-digit years per spec
https://day.js.org/docs/en/parse/string-format
Information
The text was updated successfully, but these errors were encountered: