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.

fecha.parse method is allowing an invalid and a malformed dates

See original GitHub issue

I’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:closed
  • Created 7 years ago
  • Reactions:5
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
k15acommented, Jun 8, 2018

Maybe the strict version could parse the date and format it again and then check if both strings are the same?

0reactions
taylorhakescommented, Jul 13, 2019

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

Read more comments on GitHub >

github_iconTop 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 >

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