Class Index | File Index

Classes


Namespace comb.date

Utilities for Dates
Defined in: date.js.

Namespace Summary
Constructor Attributes Constructor Name and Description
 
Method Summary
Method Attributes Method Name and Description
<static>  
comb.date.add(date, interval, amount)
Adds a specified interval and amount to a date
<static>  
comb.date.compare(date1, date2, portion)
Compares two dates
<static>  
comb.date.difference(date1, date2, interval, utc)
Finds the difference between two dates based on the specified interval
<static>  
comb.date.format(date, format, utc)
Formats a date to the specidifed format string
<static>  
comb.date.getDaysInMonth(dateObject)
Returns the number of days in the month of a date
<static>  
comb.date.getTimezoneName(dateObject)
Get the timezone of a date
<static>  
comb.date.isLeapYear(dateObject, utc)
Determines if a date is a leap year
<static>  
comb.date.isWeekend(dateObject, utc)
Determines if a date is on a weekend
<static>  
comb.date.parse(dateStr, format)
Parses a date string into a date object
Namespace Detail
comb.date
Method Detail
<static> comb.date.add(date, interval, amount)
Adds a specified interval and amount to a date
 var dtA = new Date(2005, 11, 27);
 comb.date.add(dtA, "year", 1) => new Date(2006, 11, 27);
 comb.date.add(dtA, "years", 1) => new Date(2006, 11, 27);

 dtA = new Date(2000, 0, 1);
 comb.date.add(dtA, "quarter", 1) => new Date(2000, 3, 1);
 comb.date.add(dtA, "quarters", 1) => new Date(2000, 3, 1);

 dtA = new Date(2000, 0, 1);
 comb.date.add(dtA, "month", 1) => new Date(2000, 1, 1);
 comb.date.add(dtA, "months", 1) => new Date(2000, 1, 1);

 dtA = new Date(2000, 0, 31);
 comb.date.add(dtA, "month", 1) => new Date(2000, 1, 29);
 comb.date.add(dtA, "months", 1) => new Date(2000, 1, 29);

 dtA = new Date(2000, 0, 1);
 comb.date.add(dtA, "week", 1) => new Date(2000, 0, 8);
 comb.date.add(dtA, "weeks", 1) => new Date(2000, 0, 8);

 dtA = new Date(2000, 0, 1);
 comb.date.add(dtA, "day", 1) => new Date(2000, 0, 2);

 dtA = new Date(2000, 0, 1);
 comb.date.add(dtA, "weekday", 1) => new Date(2000, 0, 3);

 dtA = new Date(2000, 0, 1, 11);
 comb.date.add(dtA, "hour", 1) => new Date(2000, 0, 1, 12);

 dtA = new Date(2000, 11, 31, 23, 59);
 comb.date.add(dtA, "minute", 1) => new Date(2001, 0, 1, 0, 0);

 dtA = new Date(2000, 11, 31, 23, 59, 59);
 comb.date.add(dtA, "second", 1) => new Date(2001, 0, 1, 0, 0, 0);

 dtA = new Date(2000, 11, 31, 23, 59, 59, 999);
 comb.date.add(dtA, "millisecond", 1) => new Date(2001, 0, 1, 0, 0, 0, 0);
Parameters:
{Date} date
{String} interval
the interval to add
  • day | days
  • weekday | weekdays
  • year | years
  • week | weeks
  • quarter | quarters
  • months | months
  • hour | hours
  • minute | minutes
  • second | seconds
  • millisecond | milliseconds
{Number} amount Optional, Default: 0
the amount to add

<static> comb.date.compare(date1, date2, portion)
Compares two dates
var d1 = new Date();
d1.setHours(0);
comb.date.compare(d1, d1) => 0

 var d1 = new Date();
 d1.setHours(0);
 var d2 = new Date();
 d2.setFullYear(2005);
 d2.setHours(12);
 comb.date.compare(d1, d2, "date") => 1
 comb.date.compare(d1, d2, "datetime") => 1

 var d1 = new Date();
 d1.setHours(0);
 var d2 = new Date();
 d2.setFullYear(2005);
 d2.setHours(12);
 comb.date.compare(d2, d1, "date"), -1);
 comb.date.compare(d1, d2, "time"), -1);
Parameters:
{Date|String} date1
the date to comapare
{Date|String} date2 Optional, Default: new Date()
the date to compare date1 againse
{"date"|"time"|"datetime"} portion
compares the portion specified
Returns:
-1 if date1 is < date2 0 if date1 === date2 1 if date1 > date2

<static> comb.date.difference(date1, date2, interval, utc)
Finds the difference between two dates based on the specified interval
var dtA, dtB;

dtA = new Date(2005, 11, 27);
dtB = new Date(2006, 11, 27);
comb.date.difference(dtA, dtB, "year") => 1

dtA = new Date(2000, 1, 29);
dtB = new Date(2001, 2, 1);
comb.date.difference(dtA, dtB, "quarter") => 4
comb.date.difference(dtA, dtB, "month") => 13

dtA = new Date(2000, 1, 1);
dtB = new Date(2000, 1, 8);
comb.date.difference(dtA, dtB, "week") => 1

dtA = new Date(2000, 1, 29);
dtB = new Date(2000, 2, 1);
comb.date.difference(dtA, dtB, "day") => 1

dtA = new Date(2006, 7, 3);
dtB = new Date(2006, 7, 11);
comb.date.difference(dtA, dtB, "weekday") => 6

dtA = new Date(2000, 11, 31, 23);
dtB = new Date(2001, 0, 1, 0);
comb.date.difference(dtA, dtB, "hour") => 1

dtA = new Date(2000, 11, 31, 23, 59);
dtB = new Date(2001, 0, 1, 0, 0);
comb.date.difference(dtA, dtB, "minute") => 1

dtA = new Date(2000, 11, 31, 23, 59, 59);
dtB = new Date(2001, 0, 1, 0, 0, 0);
comb.date.difference(dtA, dtB, "second") => 1

dtA = new Date(2000, 11, 31, 23, 59, 59, 999);
dtB = new Date(2001, 0, 1, 0, 0, 0, 0);
comb.date.difference(dtA, dtB, "millisecond") => 1
Parameters:
{Date} date1
{Date} date2 Optional, Default: new Date()
{String} interval Optional, Default: "day"
the intercal to find the difference of.
  • day | days
  • weekday | weekdays
  • year | years
  • week | weeks
  • quarter | quarters
  • months | months
  • hour | hours
  • minute | minutes
  • second | seconds
  • millisecond | milliseconds
utc

<static> comb.date.format(date, format, utc)
Formats a date to the specidifed format string
var date = new Date(2006, 7, 11, 0, 55, 12, 345);
comb.date.format(date, "EEEE, MMMM dd, yyyy") => "Friday, August 11, 2006"
comb.date.format(date, "M/dd/yy") => "8/11/06"
comb.date.format(date, "E") => "6"
comb.date.format(date, "h:m a") => "12:55 AM"
comb.date.format(date, 'h:m:s') => "12:55:12"
comb.date.format(date, 'h:m:s.SS') => "12:55:12.35"
comb.date.format(date, 'k:m:s.SS') => "24:55:12.35"
comb.date.format(date, 'H:m:s.SS') => "0:55:12.35"
comb.date.format(date, "ddMMyyyy") => "11082006"
Parameters:
date
the date to format
{String} format
the format of the date composed of the following options
  • G Era designator Text AD
  • y Year Year 1996; 96
  • M Month in year Month July; Jul; 07
  • w Week in year Number 27
  • W Week in month Number 2
  • D Day in year Number 189
  • d Day in month Number 10
  • E Day in week Text Tuesday; Tue
  • a Am/pm marker Text PM
  • H Hour in day (0-23) Number 0
  • k Hour in day (1-24) Number 24
  • K Hour in am/pm (0-11) Number 0
  • h Hour in am/pm (1-12) Number 12
  • m Minute in hour Number 30
  • s Second in minute Number 55
  • S Millisecond Number 978
  • z Time zone General time zone Pacific Standard Time; PST; GMT-08:00
  • Z Time zone RFC 822 time zone -0800
utc

<static> {Number} comb.date.getDaysInMonth(dateObject)
Returns the number of days in the month of a date
 comb.date.getDaysInMonth(new Date(2006, 1, 1)) => 28
 comb.date.getDaysInMonth(new Date(2004, 1, 1)) => 29
 comb.date.getDaysInMonth(new Date(2006, 2, 1)) => 31
 comb.date.getDaysInMonth(new Date(2006, 3, 1)) => 30
 comb.date.getDaysInMonth(new Date(2006, 4, 1)) => 31
 comb.date.getDaysInMonth(new Date(2006, 5, 1)) => 30
 comb.date.getDaysInMonth(new Date(2006, 6, 1)) => 31
Parameters:
{Date} dateObject
the date containing the month
Returns:
{Number} the number of days in the month

<static> {String} comb.date.getTimezoneName(dateObject)
Get the timezone of a date
 //just setting the strLocal to simulate the toString() of a date
 dt.str = 'Sun Sep 17 2006 22:25:51 GMT-0500 (CDT)';
 //just setting the strLocal to simulate the locale
 dt.strLocale = 'Sun 17 Sep 2006 10:25:51 PM CDT';
 comb.date.getTimezoneName(dt) => 'CDT'
 dt.str = 'Sun Sep 17 2006 22:57:18 GMT-0500 (CDT)';
 dt.strLocale = 'Sun Sep 17 22:57:18 2006';
 comb.date.getTimezoneName(dt) => 'CDT'
Parameters:
dateObject
the date to get the timezone from
Returns:
{String} the timezone of the date

<static> {Boolean} comb.date.isLeapYear(dateObject, utc)
Determines if a date is a leap year
 comb.date.isLeapYear(new Date(1600, 0, 1)) => true
 comb.date.isLeapYear(new Date(2004, 0, 1)) => true
 comb.date.isLeapYear(new Date(2000, 0, 1)) => true
 comb.date.isLeapYear(new Date(2006, 0, 1)) => false
 comb.date.isLeapYear(new Date(1900, 0, 1)) => false
 comb.date.isLeapYear(new Date(1800, 0, 1)) => false
 comb.date.isLeapYear(new Date(1700, 0, 1)) => false
Parameters:
{Date} dateObject
utc
Returns:
{Boolean} true if it is a leap year false otherwise

<static> {Boolean} comb.date.isWeekend(dateObject, utc)
Determines if a date is on a weekend
var thursday = new Date(2006, 8, 21);
var saturday = new Date(2006, 8, 23);
var sunday = new Date(2006, 8, 24);
var monday = new Date(2006, 8, 25);
comb.date.isWeekend(thursday)) => false
comb.date.isWeekend(saturday) => true
comb.date.isWeekend(sunday) => true
comb.date.isWeekend(monday)) => false
Parameters:
{Date} dateObject
the date to test
utc
Returns:
{Boolean} true if the date is a weekend

<static> {Date} comb.date.parse(dateStr, format)
Parses a date string into a date object
 var aug_11_2006 = new Date(2006, 7, 11, 0);
 comb.date.parse("08/11/06", "MM/dd/yy") => aug_11_2006
 comb.date.parse("11Aug2006", 'ddMMMyyyy') => aug_11_2006
 comb.date.parse("Aug2006", 'MMMyyyy') => new Date(2006, 7, 1)
 comb.date.parse("Aug 11, 2006", "MMM dd, yyyy") => aug_11_2006
 comb.date.parse("August 11, 2006", "MMMM dd, yyyy") => aug_11_2006
 comb.date.parse("Friday, August 11, 2006", "EEEE, MMMM dd, yyyy") => aug_11_2006
Parameters:
{String} dateStr
The string to parse
{String} format
the format of the date composed of the following options
  • G Era designator Text AD
  • y Year Year 1996; 96
  • M Month in year Month July; Jul; 07
  • w Week in year Number 27
  • W Week in month Number 2
  • D Day in year Number 189
  • d Day in month Number 10
  • E Day in week Text Tuesday; Tue
  • a Am/pm marker Text PM
  • H Hour in day (0-23) Number 0
  • k Hour in day (1-24) Number 24
  • K Hour in am/pm (0-11) Number 0
  • h Hour in am/pm (1-12) Number 12
  • m Minute in hour Number 30
  • s Second in minute Number 55
  • S Millisecond Number 978
  • z Time zone General time zone Pacific Standard Time; PST; GMT-08:00
  • Z Time zone RFC 822 time zone -0800
Returns:
{Date} the parsed date

Documentation generated by JsDoc Toolkit 2.4.0 on Fri Nov 18 2011 01:10:52 GMT-0600 (CST)