Rails' time extensions ported to JavaScript
I’ve ported Rails’ Numeric Time extensions to JavaScript since I needed to do some date calculations for a project I’m working on. Now one should be able to calculate dates in JS like this:
(5).seconds() // => 5000<br />
(2).weeks() + (2).hours() + (15).seconds() // => 1216815000<br />
(1).week().fromNow().toDate() // => Fri Sep 22 2006 19:16:32 GMT+0200 (CEST)<br />
var date = new Date(2000, 11, 18, 18, 15, 23);<br />
(2).years().since(date).toDate() // => Thu Dec 19 2002 06:15:23 GMT+0100 (CET)
Thought it could be useful for others as well.
You’ll need the latest prototype library, unit tests are included.
Download a zip with both .js file and unit tests or just the .js-file.