Class YAHOO.widget.DateMath
| Package: | YAHOO.widget |
| Class: | DateMath |
| Extends: | Object |
| Defined In: | calendar.js |
YAHOO.widget.DateMath is used for simple date manipulation. The class is a static utility
used for adding, subtracting, and comparing dates.
Public Properties
| |
DAY : String |
DateMath |
| <static> Constant field representing Day |
| |
MONTH : String |
DateMath |
| <static> Constant field representing Month |
| |
ONE_DAY_MS : Number |
DateMath |
| <static> Constant field representing one day, in milliseconds |
| |
WEEK : String |
DateMath |
| <static> Constant field representing Week |
| |
YEAR : String |
DateMath |
| <static> Constant field representing Year |
Public Methods
| |
add(Date date, String field, Number amount) : Date |
DateMath |
| Adds the specified amount of time to the this instance. |
| |
after(Date date, Date compareTo) : Boolean |
DateMath |
| Determines whether a given date is after another date on the calendar. |
| |
before(Date date, Date compareTo) : Boolean |
DateMath |
| Determines whether a given date is before another date on the calendar. |
| |
between(Date date, Date dateBegin, Date dateEnd) : Boolean |
DateMath |
| Determines whether a given date is between two other dates on the calendar. |
| |
clearTime(Date date) : Date |
DateMath |
| Clears the time fields from a given date, effectively setting the time to midnight. |
| |
findMonthEnd(Date date) : Date |
DateMath |
| Gets the last day of a month containing a given date. |
| |
findMonthStart(Date date) : Date |
DateMath |
| Gets the first day of a month containing a given date. |
| |
getDayOffset(Date date, Number calendarYear) : Number |
DateMath |
| Calculates the number of days the specified date is from January 1 of the specified calendar year.
Passing January 1 ... |
| |
getJan1(Number calendarYear) : Date |
DateMath |
| Retrieves a JavaScript Date object representing January 1 of any given year. |
| |
getWeekNumber(Date date, Number calendarYear, Number weekStartsOn) : Number |
DateMath |
| Calculates the week number for the given date. This function assumes that week 1 is the
week in which January 1 appea... |
| |
isMonthOverlapWeek(Date weekBeginDate) : Boolean |
DateMath |
| Determines if a given week overlaps two different months. |
| |
isYearOverlapWeek(Date weekBeginDate) : Boolean |
DateMath |
| Determines if a given week overlaps two different years. |
| |
subtract(Date date, Number field, Number amount) : Date |
DateMath |
| Subtracts the specified amount of time from the this instance. |
Public Events
This class has no public events.
Property Details
DAY
public String DAY
<static> Constant field representing Day
This property is defined by DateMath.
MONTH
public String MONTH
<static> Constant field representing Month
This property is defined by DateMath.
ONE_DAY_MS
public Number ONE_DAY_MS
<static> Constant field representing one day, in milliseconds
This property is defined by DateMath.
WEEK
public String WEEK
<static> Constant field representing Week
This property is defined by DateMath.
YEAR
public String YEAR
<static> Constant field representing Year
This property is defined by DateMath.
Method Details
add
public function add(Date date, String field, Number amount)
Adds the specified amount of time to the this instance.
Parameters:
date : DateThe JavaScript Date object to perform addition on
field : StringThe field constant to be used for performing addition.
amount : NumberThe number of units (measured in the field constant) to add to the date.
Returns:
This method is defined by DateMath.
after
public function after(Date date, Date compareTo)
Determines whether a given date is after another date on the calendar.
This method is defined by DateMath.
before
public function before(Date date, Date compareTo)
Determines whether a given date is before another date on the calendar.
This method is defined by DateMath.
between
public function between(Date date, Date dateBegin, Date dateEnd)
Determines whether a given date is between two other dates on the calendar.
Parameters:
date : DateThe date to check for
dateBegin : DateThe start of the range
dateEnd : DateThe end of the range
Returns:
This method is defined by DateMath.
clearTime
public function clearTime(Date date)
Clears the time fields from a given date, effectively setting the time to midnight.
This method is defined by DateMath.
findMonthEnd
public function findMonthEnd(Date date)
Gets the last day of a month containing a given date.
This method is defined by DateMath.
findMonthStart
public function findMonthStart(Date date)
Gets the first day of a month containing a given date.
This method is defined by DateMath.
getDayOffset
public function getDayOffset(Date date, Number calendarYear)
Calculates the number of days the specified date is from January 1 of the specified calendar year.
Passing January 1 to this function would return an offset value of zero.
This method is defined by DateMath.
getJan1
public function getJan1(Number calendarYear)
Retrieves a JavaScript Date object representing January 1 of any given year.
This method is defined by DateMath.
getWeekNumber
public function getWeekNumber(Date date, Number calendarYear, Number weekStartsOn)
Calculates the week number for the given date. This function assumes that week 1 is the
week in which January 1 appears, regardless of whether the week consists of a full 7 days.
The calendar year can be specified to help find what a the week number would be for a given
date if the date overlaps years. For instance, a week may be considered week 1 of 2005, or
week 53 of 2004. Specifying the optional calendarYear allows one to make this distinction
easily.
Parameters:
date : DateThe JavaScript date for which to find the week number
calendarYear : NumberOPTIONAL - The calendar year to use for determining the week number. Default is the calendar year of parameter "date".
weekStartsOn : NumberOPTIONAL - The integer (0-6) representing which day a week begins on. Default is 0 (for Sunday).
Returns:
This method is defined by DateMath.
isMonthOverlapWeek
public function isMonthOverlapWeek(Date weekBeginDate)
Determines if a given week overlaps two different months.
This method is defined by DateMath.
isYearOverlapWeek
public function isYearOverlapWeek(Date weekBeginDate)
Determines if a given week overlaps two different years.
This method is defined by DateMath.
subtract
public function subtract(Date date, Number field, Number amount)
Subtracts the specified amount of time from the this instance.
Parameters:
date : DateThe JavaScript Date object to perform subtraction on
field : NumberThe this field constant to be used for performing subtraction.
amount : NumberThe number of units (measured in the field constant) to subtract from the date.
Returns:
This method is defined by DateMath.