Farm Development

Datejs - A JavaScript Date Library

Found out about this nifty date package for JavaScript today: Datejs. Its chainable interface makes the code read very naturally:

// What date is next thursday?;
// Add 3 days to Today;
// Is today Friday?;

It also does quite a bit of natural English parsing, like Date.parse(‘next thursday’), although most date libraries support that too. I think the chainable interface stands out here as something special. Let's contrast that with some perl code to calculate yesterday, shall we??

my @lt = localtime(time - 86400);
return ($lt[5]+1900) .'-' . ($lt[4]+1) . '-' . ($lt[3]);

(Disclaimer: I didn't actually write that, but it's in a legacy app I sometimes maintain. I'm sure there is a cleaner way in perl to write that code, I just wouldn't know it, nor do I care to!)

  • Re: Datejs - A JavaScript Date Library

    Hi Kumar, Thanks for the post regarding Datejs. We really appreciate your interest and feedback. We're working hard on the library and constantly making improvements.

    Ah. That chuck of Perl is some sweet code. Here's the Datejs equivalent.;

    I've been thinking of adding .yesterday() and .tomorrow() to the list of functions as well. If added the above code could be shortened to the following.

    Date.tomorrow(); // <-- how sweet is that?

    Anywho, thanks again and keep on blog'n.

  • Re: Datejs - A JavaScript Date Library

    This is Ranjit

Note: HTML tags will be stripped. Hit enter twice for a new paragraph.

Recent Projects

  • JSTestNet

    Like botnet but for JS tests in CI.

  • Nose Nicedots

    Nose plugin that prints nicer dots.

  • Fudge

    Mock objects for testing.

  • Fixture

    Loading and referencing test data.

  • NoseJS

    Nose plugin that runs JavaScript tests for a Python project.

  • Wikir

    converts reST to various Wiki formats.