Date.Extras
date.extras.js just adds some more functionality to the date.js extensions to the Date native. They are split up so that if you have something simple to implement that you want to keep the code small (like our Date Picker, you can only include the basic date.js.
Here's what you get with date.extras.js:
Date.timeDiffInWords
var example = new Date(); console.log(example.timeDiffInWords()); /* "less than a minute ago" */ example.decrement('hour'); console.log(example.timeDiffInWords()); /* "about an hour ago" */ example.increment('hour', 2); console.log(example.timeDiffInWords()); /* "about an hour from now" */

Date.getOrdinal
Returns the ordinal for the day ("th", "nd", etc).
new Date().getOrdinal();

Date.getDayOfYear
Returns the day of the year (so Dec 31 is 365 unless it's leap year).
Date.parse("12.31.1999").getDayOfYear(); //365

Date.getLastDayOfMonth
So for Dec you'd get 31.
var dec = new Date(); dec.setMonth(11); dec.getLastDayOfMonth(); //31

Date.getWeek
Returns what week you're in of the year, so Dec 31 will return 52.
Date.parse("12.31.1999").getWeek(); //52

Additional Parsers
The biggest thing you get with date.extras.js is a whole bunch of parsers. date.js just includes the basics ("12/31/1999" and "12/31/1999 11:59pm"), while date.extras.js includes another ten.
Date.parse('1999-12-31 23:59:59')

Date.parse('1999-12-31T23:59:59+0200')

Date.parse('today')

Date.parse('tomorrow')

Date.parse('yesterday')

Date.parse('next monday')

Date.parse('1st')

Date.parse('14th October')

Date.parse('24th May, 2007')

Date.parse('May 3rd 2006')

cnet-libraries/03-native/01-date.extras.txt · Last modified: 2008/11/17 23:53