I’m trying to sort a list of dates, but I’m struggling with null dates which aren’t being handled consistently.
So I need something like:
var date = Date.parse(dateString);
if (!date) {
date = Date.MinValue;
}
but I’m struggling to find the correct syntax. Thanks
Update: The bug turned out to be a different problem. I have Datejs imported for use in another part of the project, so I hadn’t realised that Datejs defines a Date.parse() method which was overriding the standard JavaScript method.
Anyway, it turns out that Datejs has a weird bug which means it doesn’t handle dates beginning with “A” properly. So actually my null dates were being ordered correctly, it was just April and August dates were then being mixed up with them.
The fix is to use the Datejs Date.parseExact method which lets you provide a specific format string, see here.
parse() returns NaN on an impossible parse so how about just;