Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DateJS parsing mystery

I'm using DateJS to parse user-inputted dates, and getting some strange results.

  1. Date.parse("15 Jan 2010") returns Fri Jan 15 00:00:00 EST 2010 (right)

  2. Date.parse("15-Apr-2010") returns Thu Apr 15 00:00:00 EDT 2010 (right)

  3. Date.parse("15 Apr 2010") returns Thu Apr 1 00:00:00 EDT 2010 (wrong)

As far as I can tell, the d MMM yyyy input format works fine for every month except April and August; in those two cases, it returns the first of the month no matter what day is entered. Is this a bug, or is there a logical explanation I'm missing?

like image 539
Herb Caudill Avatar asked Mar 12 '10 16:03

Herb Caudill


People also ask

What can I use instead of date parse?

If the DATEPARSE function is not available for the data that you're working with, or the field you are trying to convert is a number data type, you can use the DATE function instead. The DATE function converts a number, string or date expression to a date type.

What does parsing date mean?

Definition and Usage parse() parses a date string and returns the time difference since January 1, 1970. parse() returns the time difference in milliseconds.

How to parse the date in javascript?

The parse() method takes a date string (such as "2011-10-10T14:48:00" ) and returns the number of milliseconds since January 1, 1970, 00:00:00 UTC. This function is useful for setting date values based on string values, for example in conjunction with the setTime() method and the Date object.


1 Answers

Aha: Looks like the version in the "Download" link is a good bit older than the current source. Here's the commit that fixed this bug:

Dan Yoder fixed bug with timeContext pattern where if a date included "april" or "august", the parser thought the 'a' was the beginning of a time part (as in am/pm).

The most recent version of the EN-US script is here: http://code.google.com/p/datejs/source/browse/trunk/build/date-en-US.js It would be nice if the website linked to this instead of to a zip file that hasn't been updated for a couple of years.

like image 195
Herb Caudill Avatar answered Sep 30 '22 14:09

Herb Caudill