search envelope-o feed check
Home Unanswered Active Tags New Question
user comment-o

DayPilot parse date with shortened year notation gives an error

Asked by Giliam
3 years ago.

I'm trying to parse a date using format 'd-MMM-yy' but that gives me an error.

When executing the example in API documentation (https://api.daypilot.org/daypilot-date-parse/) it works

  • DayPilot.Date.parse("12/31/2016", "M/d/yyyy");

When modifying this to the date format we use (except the use of full year notation) it works as well.

  • DayPilot.Date.parse( "10-SEP-2020", "d-MMM-yyyy");

But when modifying this to shortened year notation, as described in the documentation, it gives me an errror.

  • DayPilot.Date.parse( "10-SEP-20", "d-MMM-yy");

Am I doing something wrong or is this a bug?

An image is attached where you can see the result I get in the Chrome DevTools console.

DayPilot Pro for JavaScript 2020.3.4648 is being used here.

Answer posted by Dan Letecky [DayPilot]
3 years ago.

It was intentionally not implemented in DayPilot.Date.parse() because of the ambiguity (and the docs was not correct - it was only supported in toString()).

Anyway, it's now supported in the latest sandbox build (2020.3.4665). Please note that value will always resolve to year 2000+. Depending on your logic, you need to set your own threshold for resolving to 19xx and adjust the result accordingly:

var date = DayPilot.Date.parse( "10-SEP-88", "d-MMM-yy");
if (date && date.getYear() > 2070) {
  date = date.addYears(-100);
}
Comment posted by Giliam
3 years ago.

Thanks for adding the functionality, very much appreciated.

This question is more than 1 months old and has been closed. Please create a new question if you have anything to add.