parse with format "yyMd" gives unexpected result
See original GitHub issueI’m unsure if my expectations are off but when I parse the string “2211” and “2212” using format “yyMd” I don’t get a valid date. “2213” works.
const actualDate = parse("2211", "yyMd", new Date());
console.log(actualDate.toString());
//Invalid Date
const expectedDate = new Date("2022-01-01");
console.log(expectedDate.toString());
//Sat Jan 01 2022 01:00:00 GMT+0100 (Central European Standard Time)
Issue Analytics
- State:
- Created 2 years ago
- Comments:7
Top Results From Across the Web
SimpleDateFormat: unexpected results and unexpected parse ...
I'm having huge difficulties with simple date format. First of all, I know not all tutorials on all sites are actually good, but...
Read more >HDATE: Converting the Date Portion of a Date-Time Value to ...
The HDATE function converts the date portion of a date-time value to the date format YYMD. You can then convert the result to...
Read more >DateTime.Parse Method (System) - Microsoft Learn
Converts the string representation of a date and time to its DateTime equivalent by using culture-specific format information and a formatting style. Examples....
Read more >TIBCO FOCUS® Developing Applications Release 9.0.0
Enables use of blank delimited (Fusion) Master File syntax, and provides increased ... dates with YMD or YYMD format; or January 1901, for....
Read more >Date Parsing - Kendo UI Globalization - Documentation
This may lead to unexpected results when parsing ambiguous date strings with no delimiters. For example, the parsing of 222015 with a dMyyyy...
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
my point is this is just an accepted side effect of using a “fuzzy” format like
yyMd
, this is just my personal opinion,maybe we should @ the member of this lib to confirm the situationYeah I agree that the
yyMd
format is probably prone to these errors.I was however surprised that
parse
rather choose to return an invalid date since it can match11
to a month with no day and didn’t try matching the11
to January 1st.