-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
InvalidDate using customParseFormat with strict mode #1561
Comments
EX 1)
In b) case, meridiem is not the problem. EX 2) |
Example 1 fails, because the best matching format Example 2 fails, because dayjs fails in strict mode, when the parsed date has an offset different from the current time zone. This would be fixed by pr #1914. |
Example #1:
const time = dayjs('04:59:00.900 PM', ['HH:mm:ss.SSSSSSS', 'HH:mm:ss', 'HH:mm', 'h:mm A', 'h:mm:ss A', 'h:mm:ss.SSS A'], true); // InvalidDate
console.log(time.format('HH:mm:ss.SSSSSSSSS')); //InvalidDate
Example #2:
const parsed = dayjs(
'2021-06-30T16:55+00:00',
[
'MM-DD-YYYY h:mm A',
'MM-DD-YYYY h:mm:ss A',
'MM-DD-YYYY h:mm:ss.SSSSSSSSS A',
'YYYY-MM-DD[T]HH:mm:ss.SSSSSSSSSZ',
'YYYY-MM-DD[T]HH:mm:ssZ',
'YYYY-MM-DD[T]HH:mmZ',
],
true,
); //InvalidDate
console.log(parsed.isValid); //returns false
Expected behavior
Both examples should return a valid date like moment does.
Formatting #1 should return '16:59:00.900000000'
It seems that #2 has an issue with the meridiem since the following works:
console.log("without meridiem ", dayjs('04:59:00.900','HH:mm:ss.SSS',true).format('h:mm:ss.SSS A')); //Valid date
console.log("with meridiem ", dayjs('04:59:00.900 PM','h:mm:ss.SSS A',true)).format('h:mm:ss.SSS A')); //InvalidDate
The text was updated successfully, but these errors were encountered: