fecha.parse method is allowing an invalid and a malformed dates
See original GitHub issueI’d expected to get a false
return or an exception when I called the fecha.parse
method with an invalid and a malformed dates. But it parsed them successfully. Is this the desired result?
Invalid: Date parts are not in the valid ranges (12 >= Month >= 1, 31>= Day>= 1, 23>=Hour>= 0 …)
fecha.parse('2016-44-99', 'YYYY-MM-DD'); // Sat Nov 12 2016 21:39:00 GMT+0300
fecha.parse('2016-11-11 44:44', 'YYYY-MM-DD HH:mm'); // Sat Nov 12 2016 20:44:00 GMT+0300
Malformed: Supplied date string does not match the format
fecha.parse('2016-1-1', 'YYYY-MM-DD'); // Fri Jan 01 2016 01:00:00 GMT+0400
fecha.parse('2016-11-11 3:4', 'YYYY-MM-DD HH:mm'); // Fri Nov 11 2016 03:04:00 GMT+0300
Invalid & Malformed:
fecha.parse('2016-9876-123', 'YYYY-MM-DD'); // Tue Apr 16 2024 00:00:00 GMT+0300
fecha.parse('2016-11-11 4433:3344', 'YYYY-MM-DD HH:mm'); // Sat Nov 12 2016 20:33:00 GMT+0300
Tested on: Google Chrome Version 54.0.2840.71 m (Windows 10)
Thanks,
Issue Analytics
- State:
- Created 7 years ago
- Reactions:5
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Why does Date.parse give incorrect results? - Stack Overflow
parse method was completely implementation dependent ( new Date(string) is equivalent to Date.parse(string) except the latter returns a number ...
Read more >RangeError: invalid date - JavaScript - MDN Web Docs
The JavaScript exception "invalid date" occurs when a string leading to an invalid date has been provided to Date or Date.parse().
Read more >taylorhakes/fecha - Lightweight Date Formatting and Parsing
parse accepts a Date string and a string format and returns a Date object. See below for available format tokens. NOTE: parse will...
Read more >to_date function | Databricks on AWS
In Databricks Runtime, if spark.sql.ansi.enabled is false , the function returns NULL instead of an error for malformed dates.
Read more >DateFormat (Java Platform SE 7 ) - Oracle Help Center
DateFormat is an abstract class for date/time formatting subclasses which formats and parses dates or time in a language-independent manner.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Maybe the strict version could parse the date and format it again and then check if both strings are the same?
I am going to close this issue. If someone would like to submit a PR to add a strict version (which doesn’t add a lot of code), I would be happy to add it