Mad Cool Date Library
Written by on November 27th, 2007 in Ajax News.
Ok, I’ve seen some cool libraries in my time but I’ve just found one that is ssssooo cool that I didn’t want to wait to post about it until tomorrow (sorry Dion!).
So I get this email from a bud asking me to check out this date handling library and I’m figuring “great, Yet Another Date Library”. So I jump on over to DateJS.com to check it out and I’m presented with a nice looking site. I mean the little ninja dude at top is pretty slick! Anyways, I digress.
I start reading up on it and I see the usual pitch:
Datejs is an open-source JavaScript Date Library.
Comprehensive, yet simple, stealthy and fast. Datejs has passed all trials and is ready to strike. Datejs doesn’t just parse strings, it slices them cleanly in two.
Read that before, must be the same ole, blah, blah. So I look for like a date picker or something and all I see is a text box. Hmm. I see some suggestions listed below it:
So I give it a go and…woah!
Okay, lucky try. I know if I try that t+5years, it’s gonna choke.
Holy cow!!! All I have to say is wow. This is a VERY cool date library and definitely unique. I’ve not seen anything like this.
DateJS is the brainchild of Geoffrey McGill and the team at Coolite. It was developed to handle both parsing, formatting and processing of dates within the JS language. Apart from its incredible parsing capabilities, it also supports a TON of different language formats!
All 150+ CultureInfo files have been pre-compiled and are available within the same /build/ folder as date.js. Each culture file includes translations for many of the strings used in the Datejs library. Some strings have not been translated, although will be filled in over time as the community contributes.
The widget does a complete Date.parse(text) on each keystroke. Notice that no ‘date format’ is passed into the Parser. The Parser figures everything out on it’s own.
The API is also so simple to use. I mean just look below at the code examples. It doesn’t get much easier then that:
// What date is next thrusday?
Date.today().next().thursday();
// Add 3 days to Today
Date.today().add(3).days();
// Is today Friday?
Date.today().is().friday();
// Number fun
(3).days().ago();
// 6 months from now
var n = 6;
n.months().fromNow();
// Set to 8:30 AM on the 15th day of the month
Date.today().set({ day: 15, hour: 8, mintue: 30 });
// Convert text into Date
Date.parse(‘today’);
Date.parse(‘t + 5 d’); // today + 5 days
Date.parse(‘next thursday’);
Date.parse(‘February 20th 1973′);
Date.parse(‘Thu, 1 July 2004 22:30:00′);
Overall, Datejs is REALLY impressive and I’m definitely going to see where I can use it in. Datejs is released under the MIT License and available for download at GoogleCode.
Source: Ajaxian
Original Article: http://feeds.feedburner.com/~r/ajaxian/~3/191531967/mad-cool-date-library



