Show:

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

Methods

_absFloor

(
  • n
)
protected

Returns the largest absolute integer less than or equal to a number.

Parameters:

  • n Object

_addDays

(
  • d
  • nDays
)
private

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)

add

(
  • date
  • field
  • amount
)
Date

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

(
  • date
  • compareTo
)
Boolean

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

(
  • date
  • compareTo
)
Boolean

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

(
  • date
  • dateBegin
  • dateEnd
)
Boolean

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
)
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

clone

(
  • date
)
Date

Clones the passed date object.

Parameters:

  • date Date

    The JavaScript Date to clone

Returns:

Date:

The JavaScript Date cloned

compare

(
  • d1
  • d2
)
Boolean

Compare dates.

Parameters:

  • d1 Date

    The JavaScript Date object to compare

  • d2 Date

    The JavaScript Date object to compare

Returns:

Boolean:

copyHours

(
  • d1
  • d2
)

Copies hours, minutes, seconds and milliseconds.

Parameters:

  • d1 Object
  • d2 Object

countDays

(
  • d1
  • d2
)

Counts the number of days between two dates excluding the last one. The order of the dates is not important.

For example, if the first one is March 8, 2015 and the second one is March 14, 2015, then the returned value should be 6. If the first one is March 29, 2015 and the second one is April 4, 2015, then the returned value should be 6.

This method iterates over all days between the dates so it can be slow for dates that are too much far from one another.

Parameters:

  • d1 Object

    One of the days

  • d2 Object

    The other day

Returns:

the number of days between the two dates.

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

findMonthStart

(
  • date
)
Date

Getss 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

(
  • y
  • m
  • d
)
Date

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

(
  • d1
  • d2
)
Number

Calculates the number of days between the specified dates.

Parameters:

Returns:

Number:

The number of days

getDayOffset

(
  • date
  • calendarYear
)
Number

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

getDaysInMonth

(
  • year
  • month
)
Date

Gets date from a given month and year.

Parameters:

  • year Object
  • month Object

Returns:

Date:

getFirstDayOfWeek

(
  • dt
  • startOfWeek
)
Date

Gets 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

getHoursOffset

(
  • d1
  • d2
)
Number

Calculates the number of hours between the specified dates.

Parameters:

Returns:

Number:

The number of hours

getJan1

(
  • calendarYear
)
Date

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.

getMinutesOffset

(
  • d1
  • d2
)
Number

Calculates the number of minutes between the specified dates.

Parameters:

Returns:

Number:

The number of minutes

getOffset

(
  • d1
  • d2
  • constantAmount
)

Returns the amount of time subtracted.

Parameters:

  • d1 Object
  • d2 Object
  • constantAmount Object

getSecondsOffset

(
  • d1
  • d2
)
Number

Calculates the number of seconds between the specified dates.

Parameters:

Returns:

Number:

The number of seconds

getWeekNumber

(
  • date
  • firstDayOfWeek
  • janDate
)
Number

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.

isDayBoundary

(
  • date1
  • date2
)

Checks if the {date2} is the next day at 00:00:00.

Parameters:

Returns:

boolean

isDayOverlap

(
  • date1
  • date2
)

Checks if the passed date is between two days.

Parameters:

Returns:

boolean

isMonthOverlapWeek

(
  • weekBeginDate
)
Boolean

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.

isMonWedOrFri

(
  • date
)

Checks if the passed date is a Monday, Wednesday or Friday.

Parameters:

Returns:

boolean

isNextDay

(
  • date1
  • date2
)

Checks if the {date2} is the next day.

Parameters:

Returns:

boolean

isSameMonth

(
  • d1
  • d2
)

Checks if the passed dates are in the same month.

Parameters:

Returns:

boolean

isToday

(
  • date
)

Checks if the passed date is today.

Parameters:

Returns:

boolean

isTueOrThu

(
  • date
)

Checks if the passed date is a Tuesday or Thursday.

Parameters:

Returns:

boolean

isWeekDay

(
  • date
)

Checks if the passed date is a week day.

Parameters:

Returns:

boolean

isYearOverlapWeek

(
  • weekBeginDate
)
Boolean

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.

safeClearTime

(
  • date
)
Date

Clears the time fields from a given date, effectively setting the time to 12 noon. This is "safe" because clones the date before clear, not affecting the passed reference.

Parameters:

  • date Date

    The JavaScript Date for which the time fields will be cleared

Returns:

Date:

The JavaScript Date cleared of all time fields

subtract

(
  • date
  • field
  • amount
)
Date

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

toIsoTimeString

(
  • date
  • showSeconds
)
String

Converts a date to ISO time format.

Parameters:

  • date Object
  • showSeconds Object

Returns:

String:

time

toLastHour

(
  • date
)
Date

Sets the time fields from a given date to the last possible hour.

Parameters:

  • date Date

    The JavaScript Date for which the time fields will be set to the last possible hour

Returns:

Date:

The JavaScript Date set to the last possible hour

toMidnight

(
  • date
)
Date

Sets the time fields from a given date to midnight.

Parameters:

  • date Date

    The JavaScript Date for which the time fields will be set to midnight

Returns:

Date:

The JavaScript Date set to midnight

toUsTimeString

(
  • date
  • padHours
  • omitMinutes
  • hideAmPm
)
String

Converts a date to US time format.

Parameters:

  • date Object
  • padHours Object
  • omitMinutes Object
  • hideAmPm Object

Returns:

String:

time

Properties

DAY

String final static

Constant field representing Day.

HOUR

String final static

Constant field representing Hour.

MAX_MONTH_LENGTH

Number final static

Constant field representing the number of maximum days in a month.

MINUTES

String final static

Constant field representing Minutes.

MONTH

String final static

Constant field representing Month.

ONE_DAY_MS

Number final static

Constant field representing one day, in milliseconds.

ONE_HOUR_MS

Number final static

Constant field representing one hour, in milliseconds.

ONE_MINUTE_MS

Number final static

Constant field representing one minute, in milliseconds.

ONE_SECOND_MS

Number final static

Constant field representing one second, in milliseconds.

SECONDS

String final static

Constant field representing Seconds.

WEEK

String final static

Constant field representing Week.

WEEK_LENGTH

Number final static

Constant field representing the number of maximum days in a week.

WEEK_ONE_JAN_DATE

Number static

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

String final static

Constant field representing Year.