dayjs icon indicating copy to clipboard operation
dayjs copied to clipboard

fix: better nil check on utils

Open pedronauck opened this issue 5 years ago • 3 comments

When you try to pass an empty string for the constructor an obtrusive Invalid date error is showing. Something like that doesn't work: dayjs('').format(YYYY-MM-DD') and breaks the system.

What I did is just check if a string is an empty string or is undefined or null.

pedronauck avatar Nov 16 '20 21:11 pedronauck

Thanks. But I don't think '' is a valid date in js.

iamkun avatar Nov 23 '20 09:11 iamkun

I know that '' isn't a valid date, but sometimes you can't control all data in some systems, this is a common cases (mainly in legacy systems), and update to dayjs can be something hard since if you have something like '' inside the constructor it will break the entire system. Handle properly with that could be something to prevent system break-outs and turn dayjs able for a lot of developers.

I talking to you about that because of a system of one of my customers is a little legacy and this happened when I try to change of moment to dayjs (was thousand of files).

pedronauck avatar Nov 25 '20 02:11 pedronauck

Alright, I do think adding a custom plugin to parse '' is a better choice. Cause if we accept this PR, it will also affect a lot of projects that depend on dayjs that treat '' as invalid

iamkun avatar Nov 26 '20 13:11 iamkun