Print Friendly

# 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

Property | Defined By
--- | ---
| 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

Method | Defined By
--- | ---
| 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` : Date
  The JavaScript Date object to perform addition on
- `field` : String
  The field constant to be used for performing addition.
- `amount` : Number
  The number of units (measured in the field constant) to add to the date.

Returns:

- `Date`
  The resulting Date object

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.
Parameters:

- `date` : Date
  The Date object to compare with the compare argument
- `compareTo` : Date
  The Date object to use for the comparison

Returns:

- `Boolean`
  true if the date occurs after the compared date; false if not.

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.
Parameters:

- `date` : Date
  The Date object to compare with the compare argument
- `compareTo` : Date
  The Date object to use for the comparison

Returns:

- `Boolean`
  true if the date occurs before the compared date; false if not.

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` : Date
  The date to check for
- `dateBegin` : Date
  The start of the range
- `dateEnd` : Date
  The end of the range

Returns:

- `Boolean`
  true if the date occurs between the compared dates; false if not.

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.
Parameters:

- `date` : Date
  The JavaScript Date for which the time fields will be cleared

Returns:

- `Date`
  The JavaScript Date cleared of all time fields

This method is defined by DateMath.

### findMonthEnd

`public function findMonthEnd(`Date date`)`
Gets the last day of a month containing a given date.
Parameters:

- `date` : Date
  The JavaScript Date used to calculate the month end

Returns:

- `Date`
  The JavaScript Date representing the last day of the month

This method is defined by DateMath.

### findMonthStart

`public function findMonthStart(`Date date`)`
Gets the first day of a month containing a given date.
Parameters:

- `date` : Date
  The JavaScript Date used to calculate the month start

Returns:

- `Date`
  The JavaScript Date representing the first day of the month

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.
Parameters:

- `date` : Date
  The JavaScript date for which to find the offset
- `calendarYear` : Number
  The calendar year to use for determining the offset

Returns:

- `Number`
  The number of days since January 1 of the given year

This method is defined by DateMath.

### getJan1

`public function getJan1(`Number calendarYear`)`
Retrieves a JavaScript Date object representing January 1 of any given year.
Parameters:

- `calendarYear` : Number
  The calendar year for which to retrieve January 1

Returns:

- `Date`
  January 1 of the calendar year specified.

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` : Date
  The JavaScript date for which to find the week number
- `calendarYear` : Number
  OPTIONAL - The calendar year to use for determining the week number. Default is the calendar year of parameter "date".
- `weekStartsOn` : Number
  OPTIONAL - The integer (0-6) representing which day a week begins on. Default is 0 (for Sunday).

Returns:

- `Number`
  The week number of the given date.

This method is defined by DateMath.

### isMonthOverlapWeek

`public function isMonthOverlapWeek(`Date weekBeginDate`)`
Determines if a given week overlaps two different months.
Parameters:

- `weekBeginDate` : Date
  The JavaScript Date representing the first day of the week.

Returns:

- `Boolean`
  true if the date 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.
Parameters:

- `weekBeginDate` : Date
  The JavaScript Date representing the first day of the week.

Returns:

- `Boolean`
  true if the date 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` : Date
  The JavaScript Date object to perform subtraction on
- `field` : Number
  The this field constant to be used for performing subtraction.
- `amount` : Number
  The number of units (measured in the field constant) to subtract from the date.

Returns:

- `Date`
  The resulting Date object

This method is defined by DateMath.

yui-ext - Copyright © 2006 Jack Slocum. | Yahoo! UI - Copyright © 2006 Yahoo! Inc.
All rights reserved.