-
-
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
format throws when used on "Invalid Date" with advancedformat + timezone + utc #1558
Comments
In typescript? |
In Javascript var dayjs = require("dayjs");
console.log(dayjs(null).format('lll z')); // Invalid Date In Typescript import dayjs from 'dayjs'
console.log(dayjs(null).format('lll z')); returned error TS2769: No overload matches this call. i tried reproduced this issue. but not reproduced. give more details for this issue? |
My bad, I should have mentionned that the index.js const dayjs = require("dayjs");
const utc = require("dayjs/plugin/utc");
const timezone = require("dayjs/plugin/timezone");
const advancedFormat = require("dayjs/plugin/advancedFormat");
dayjs.extend(utc)
dayjs.extend(timezone)
// dayjs.extend(advancedFormat) // When this is enabled, dayjs throws. When it's not, it outputs 'Invalid Date'.
console.log(dayjs(null).format('lll z')) |
i checked plugin if you want use the original https://day.js.org/docs/en/plugin/advanced-format check this document. Apart from this, it seems that the returned values of moment and dayjs are different. so need fix that. |
I completely missed the section in the advancedFormat docs where it says it changes the format function of dayjs. Still, throwing rather than giving Invalid Date is a weird edge case that I'm sure I'm not the only one to catch on deployed code. 😁 I made sure my code does not give a null parameter to an advancedFormat constructor for now, thanks again for working on this |
- iamkun#1558 - add validation for invalid date in plugin advancedFormat
Merged complete |
Describe the bug
When using the following format string on dayjs(null) the resulting date is "Invalid Date"
When using the following string, dayjs throws
Thrown error:
Expected behavior
dayjs should display "Invalid Date" and not throw an error
Information
The text was updated successfully, but these errors were encountered: