question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Date validity check does not work correctly

See original GitHub issue

Describe the bug I tried to parse 2020-13-13 with this library and its isValid() check returned true while I expected it to return false

Expected behavior I expected the date is valid check to return false

Information

  • Day.js Version [1.8.34]
  • OS: [iOS]
  • Browser [Node]
  • Time zone: [e.g. GMT+03:00 EAT (East African Time)]

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
iamkuncommented, Aug 25, 2020

You may specify a boolean for the last argument to use strict parsing. Strict parsing requires that the format and input match exactly, including delimiters.

dayjs('1970-00-00', 'YYYY-MM-DD').isValid() // true
dayjs('1970-00-00', 'YYYY-MM-DD', true).isValid() // false
dayjs('1970-00-00', 'YYYY-MM-DD', 'es', true).isValid() // false

https://day.js.org/docs/en/parse/string-format

0reactions
iamkuncommented, Sep 24, 2020

Cool! I’ll close this issue since it’s been solved. Feel free to reopen if you have updates on this

Read more comments on GitHub >

github_iconTop Results From Across the Web

Detecting an "invalid date" Date instance in JavaScript
You can check the validity of a Date object d via d instanceof Date && isFinite(d). To avoid cross-frame issues, one could replace...
Read more >
Program to check if a date is valid or not - GeeksforGeeks
Given a date, check if it is valid or not. It may be assumed that the given date is in range from 01/01/1800...
Read more >
A Date is not valid error occurs when Project Connector is ...
Fixes a problem where a "Date is not valid" error occurs when Project Connector is running on a computer where the date setting...
Read more >
Use Excel Data Validation for Entering Dates - Contextures
Restrict Date to Current Year​​ To test the data validation, enter a date that is not in the current year.
Read more >
Date and Time validation not working - ServiceNow Community
I am looking to validate the date and time field on a catalog item. I am using the script below but for some...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found