Skip to content
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('2014-01-33').format('DD/MM/YYYY') doesn't return invalid date #2114

Open
hamzahamidi opened this issue Nov 6, 2022 · 5 comments
Open

Comments

@hamzahamidi
Copy link
Contributor

hamzahamidi commented Nov 6, 2022

Describe the bug

const day = dayjs('2014-01-33').format('DD/MM/YYYY');
console.log(lastDay); // return 02/02/2014

doesn't return invalid date

Expected behavior
Should the above expression return invalid date or is this the expected behavior?

Information

  • Day.js Version: v1.11.6
  • OS: Debian version 11.5
  • Browser: Chrome 107.0.5304.87
  • Time zone: +1
@hamzahamidi hamzahamidi changed the title const lastDay = dayjs('2014-01-33').format('DD/MM/YYYY') console.log(lastDay); dayjs('2014-01-33').format('DD/MM/YYYY') doesn't return invalid date Nov 6, 2022
@lessfish
Copy link

lessfish commented Nov 7, 2022

I thinks it's the expected behavior

@Bykiev
Copy link

Bykiev commented Nov 7, 2022

Hi, this is not a bug, if you wish strict parsing, you can pass true as third parameter.
Read more here

@willianfalbo
Copy link

willianfalbo commented Dec 7, 2022

Hey @Bykiev, it is definitely a bug! What is the reason for it?
It doesn't make sense allowing a date as 2014-01-33. It is an invalid date!

Other libs such as moment, handles it as expected! Look at this example:
image

If that is the case, we cannot rely on this lib!

@Bykiev
Copy link

Bykiev commented Dec 8, 2022

@willianfalbo, if it's described in the docs it's not a bug

There is a table of diff with moment library on the linked page

Differences to moment

title parameters dayjs moment
invalid date with overflow ('35/22/2010 99:88:77', 'DD-MM-YYYY HH:mm:ss') '08-11-2011 04:29:17' 'Invalid date'
invalid date with overflow, strict ('35/22/2010 99:88:77', 'DD-MM-YYYY HH:mm:ss', true) 'Invalid Date' 'Invalid date'
'0' day or month (using default values) ('1970-00-00', 'YYYY-MM-DD') '1970-01-01' 'Invalid date'
'0' day or month (using default values), strict ('1970-00-00', 'YYYY-MM-DD', true) 'Invalid Date' 'Invalid date'
date not matching format ('10/12/2014', 'YYYY-MM-DD') '01-01-2014' '12-20-2010'
date not matching format, strict ('10/12/2014', 'YYYY-MM-DD', true) 'Invalid Date' 'Invalid date'
first match vs. longest match ('2012-05-28 10:21:15', ['YYYY', 'YYYY-MM-DD', 'YYYY-MM-DD HH:mm:ss']) '2012-01-01 00:00:00' '2012-05-28 10:21:15'
first match vs. longest match, strict ('2012-05-28 10:21:15', ['YYYY', 'YYYY-MM-DD', 'YYYY-MM-DD HH:mm:ss'], true) '2012-05-28 10:21:15' '2012-05-28 10:21:15'

@willianfalbo
Copy link

Hi @Bykiev, you are right, it is in the docs though!

Well, if dayjs accepts this, there is nothing we can do. Btw, our team replaced this lib to moment as it is more reliable in this context. Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants