Yahoo! UI Library

Calendar  2.7.0

Yahoo! UI Library > calendar > YAHOO.widget.DateMath
Search:
 
Filters

Class YAHOO.widget.DateMath

YAHOO.widget.DateMath is used for simple date manipulation. The class is a static utility used for adding, subtracting, and comparing dates.

Properties

DAY - static final String

Constant field representing Day

MONTH - static final String

Constant field representing Month

ONE_DAY_MS - static final Number

Constant field representing one day, in milliseconds

WEEK - static final String

Constant field representing Week

WEEK_ONE_JAN_DATE - static Number

Constant field representing the date in first week of January which identifies the first week of the year.

In the U.S, Jan 1st is normally used based on a Sunday start of week. ISO 8601, used widely throughout Europe, uses Jan 4th, based on a Monday start of week.


YEAR - static final String

Constant field representing Year

Methods

_addDays

private void _addDays ( d , nDays )
Private helper method to account for bug in Safari 2 (webkit < 420) when Date.setDate(n) is called with n less than -128 or greater than 127.

Fix approach and original findings are available here: http://brianary.blogspot.com/2006/03/safari-date-bug.html

Parameters:
d <Date> JavaScript date object
nDays <Number> The number of days to add to the date object (can be negative)
Returns: void

add

Date add ( date , field , 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

after

Boolean after ( 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.

before

Boolean before ( 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.

between

Boolean between ( date , dateBegin , 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.

clearTime

Date clearTime ( date )
Clears the time fields from a given date, effectively setting the time to 12 noon.
Parameters:
date <Date> The JavaScript Date for which the time fields will be cleared
Returns: Date
The JavaScript Date cleared of all time fields

findMonthEnd

Date findMonthEnd ( 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

findMonthStart

Date findMonthStart ( 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

getDate

Date getDate ( y , m , d )
Returns a new JavaScript Date object, representing the given year, month and date. Time fields (hr, min, sec, ms) on the new Date object are set to 0. The method allows Date instances to be created with the a year less than 100. "new Date(year, month, date)" implementations set the year to 19xx if a year (xx) which is less than 100 is provided.

NOTE:Validation on argument values is not performed. It is the caller's responsibility to ensure arguments are valid as per the ECMAScript-262 Date object specification for the new Date(year, month[, date]) constructor.

Parameters:
y <Number> Year.
m <Number> Month index from 0 (Jan) to 11 (Dec).
d <Number> (optional) Date from 1 to 31. If not provided, defaults to 1.
Returns: Date
The JavaScript date object with year, month, date set as provided.

getDayOffset

Number getDayOffset ( date , 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

getFirstDayOfWeek

Date getFirstDayOfWeek ( dt , startOfWeek )
Get the first day of the week, for the give date.
Parameters:
dt <Date> The date in the week for which the first day is required.
startOfWeek <Number> The index for the first day of the week, 0 = Sun, 1 = Mon ... 6 = Sat (defaults to 0)
Returns: Date
The first day of the week

getJan1

Date getJan1 ( 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.

getWeekNumber

Number getWeekNumber ( date , firstDayOfWeek , janDate )
Calculates the week number for the given date. Can currently support standard U.S. week numbers, based on Jan 1st defining the 1st week of the year, and ISO8601 week numbers, based on Jan 4th defining the 1st week of the year.
Parameters:
date <Date> The JavaScript date for which to find the week number
firstDayOfWeek <Number> The index of the first day of the week (0 = Sun, 1 = Mon ... 6 = Sat). Defaults to 0
janDate <Number> The date in the first week of January which defines week one for the year Defaults to the value of YAHOO.widget.DateMath.WEEK_ONE_JAN_DATE, which is 1 (Jan 1st). For the U.S, this is normally Jan 1st. ISO8601 uses Jan 4th to define the first week of the year.
Returns: Number
The number of the week containing the given date.

isMonthOverlapWeek

Boolean isMonthOverlapWeek ( 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.

isYearOverlapWeek

Boolean isYearOverlapWeek ( 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.

subtract

Date subtract ( date , field , 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


Copyright © 2009 Yahoo! Inc. All rights reserved.