Date.Extras

docs

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" */
execute this code

Date.getOrdinal

Returns the ordinal for the day ("th", "nd", etc).

new Date().getOrdinal();
execute this code

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
execute this code

Date.getLastDayOfMonth

So for Dec you'd get 31.

var dec = new Date();
dec.setMonth(11);
dec.getLastDayOfMonth(); //31
execute this code

Date.getWeek

Returns what week you're in of the year, so Dec 31 will return 52.

Date.parse("12.31.1999").getWeek(); //52
execute this code

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')
execute this code
Date.parse('1999-12-31T23:59:59+0200')
execute this code
Date.parse('today')
execute this code
Date.parse('tomorrow')
execute this code
Date.parse('yesterday')
execute this code
Date.parse('next monday')
execute this code
Date.parse('1st')
execute this code
Date.parse('14th October')
execute this code
Date.parse('24th May, 2007')
execute this code
Date.parse('May 3rd 2006')
execute this code

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