Name:
Location: United Kingdom

I am a software developer and consultant with more than a quarter of a century of technology change and challenges to draw experience from. While I maintain and exercise some skills from the dark ages of computing I also enjoy taming the new technologies as they turn up – always looking for ways to deliver truly effective software systems to my customers.

Thursday, November 29, 2007

JavaScript Dates

Sometimes I have to kick myself – I had better confess all.

I followed a link, proclaiming the “holy grail” of JavaScript Date functionality had been found, to a post by Mark Hopkins at Mashable demonstrating some of the functionality of date.js.

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.
http://www.datejs.com/2007/11/27/getting-started-with-datejs/

Currently the library supports 150+ cultures and including the appropriate
culture-specific date.js file the Parser will automatically switch to
the correct
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
files. See
http://www.datejs.com/download/

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.

3 Comments:

Blogger Mike Griffiths said...

A brilliant post by Erik Naggum on the subject of dates and time is well worth a look. It covers the fascinating complexity of storing and representing such a deceptively simple concept.

5:24 AM  
Blogger hfoda1977 said...

Dear Mike,
I am Haitham from Egypt
Your dummy SMTP server is very elegent piece of code.
Can you advice me how to convert it to real SMTP ?
What is the missing part ?
Regards,
Haitham
hfoda1977@yahoo.com

12:52 PM  
Blogger Mike Griffiths said...

First off, the comment from Haitham relates to a post back in January 2006 and some code resting at http://www.dotnetcode.co.uk/dummysmtp.aspx

This is a Dummy SMTP server because it is designed to help in the testing of applications that send email. This server just "catches" the emails and dumps them to a text file. This can save a lot of hassle when trying to test against your live SMTP server.

What's missing? Well this server never sends any of the emails out to a net mail server.

1:22 AM  

Post a Comment

Links to this post:

Create a Link

<< Home