-
-
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
dayjs("2021-01-26T14:25:04.871Z", "YYYY-MM-DDTHH:mm:ss.SSSZ") doesn't work #1358
Comments
fixed in #1359 |
@beckyconning Since this is not released yet so I tried to manually modify the const format = 'YYYY-MM-DDTHH:mm:ss.SSSZ';
const inputDate = '1993-12-01T10:22:33.128Z';
const isDateValid = dayjs(inputDate, format, true).isValid(); // returns false I use this Zulu format a lot in my open source lib and this is the only piece missing to migrate to DayJS so I then cloned the project and tried adding this unit test in describe('Strict mode', () => {
// ...
it('zulu', () => {
const input = '2021-01-26T15:38:43.000Z'
const format = 'YYYY-MM-DDTHH:mm:ss.SSSZ'
expect(dayjs(input, format).isValid()).toBe(true) // ok
expect(dayjs(input, format, true).isValid()).toBe(true) // fails
})
}) I traced the problem up to the these lines 227-229 // in my case date is '2021-01-26T15:38:43.000Z'
// and this.format() is '2021-01-26T10:38:43.000-05:00'
// so they are not strictly equal and it fails
if (isStrict && date !== this.format(format)) {
this.$d = new Date('')
} |
When I escape the 'Z' as such
(don't forget to extend customParseFormat!) |
oh ok I didn't know we had to escape it |
the last 2 lines illustrate one of the differences of strict VS non-strict: only when using strict, a 13th month is considered invalid |
Describe the bug
dayjs("2021-01-26T14:25:04.871Z", "YYYY-MM-DDTHH:mm:ss.SSSZ")
doesn't workmoment("2021-01-26T14:25:04.871Z", "YYYY-MM-DDTHH:mm:ss.SSSZ")
worksExpected behavior
Should work as moment does treating Z as +00:00
Information
The text was updated successfully, but these errors were encountered: