Sometimes I have to kick myself – I had better confess all.
Very good I thought although I noted that the demonstration posited that 05/11/07 was a date in May (a peculiarly US idea). After I had followed the link to http://datejs.com to download the code I dropped by the project Issues page – but somehow completely missed the main project page (to be fair to myself these are often devoid of anything useful).
I reported my issue with the date although I had noted that when a date was unambiguous (say 23/11/07) date.js recognised the normal day, month, year order. My shame was that I had not looked at the code before jumping in – I just thought it was an issue that had been skipped while the project was still in Alpha.
I got a very nice email explaining about the culture settings which I quote in full below:
Please check out the Getting Started with Datejs tutorial.
Currently the library supports 150+ cultures and including the appropriate
culture-specific date.js file the Parser will automatically switch to
parsing order for your country/culture/language.
The sample on the Datejs home page uses the "en-US" CultureInfo file
which expects a
dateElementOrder of "mdy". We're in Canada and use the "date-en-CA.js"
file in all
our internal apps. In Canada the expected dateElement order is "dmy".
The full download package includes all 150+ pre-compiled CultureInfo
I hope my humble apology and this post makes amends for my wasting the team’s time.
What’s all the fuss about? Well date.js has a capacity to take just about any user input (no matter how formatted or descriptive) and turns it into a date.
date.js reminds me of some very old code that is still used in some VMS applications I maintain that was written (by my brother I think) to do a similar “trick”. The user can enter (say) “t” for today, “t+2” for the day after tomorrow, use “long” or “short” date formats and always (well nearly always) end up with a sensible date that can be stored or used by the application.
Date.js goes rather further than that. It offers some sophisticated date manipulation, date comparison and date formatting options – frankly I can’t see anything left out.
The code is published under the generous MIT license so you can use it as part of any sort of application.
There are some open issues with date.js (to be expected in an Alpha) but I am sure that this code is going to end up in my toolkit. Check it out or monitor the main project page to await a full release.