A.DataType.DateMath Class
alloy-ui/src/aui-datatype/js/aui-datatype.js:79
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
.
Index
Methods
- _absFloor
- _addDays
- add
- after
- before
- between
- clearTime
- clone
- compare
- copyHours
- countDays
- findMonthEnd
- findMonthStart
- getDate
- getDayOffset
- getDayOffset
- getDaysInMonth
- getFirstDayOfWeek
- getHoursOffset
- getJan1
- getMinutesOffset
- getOffset
- getSecondsOffset
- getWeekNumber
- isDayBoundary
- isDayOverlap
- isMonthOverlapWeek
- isMonWedOrFri
- isNextDay
- isSameMonth
- isToday
- isTueOrThu
- isWeekDay
- isYearOverlapWeek
- safeClearTime
- subtract
- toIsoTimeString
- toLastHour
- toMidnight
- toUsTimeString
Properties
- DAY static
- HOUR static
- MAX_MONTH_LENGTH static
- MINUTES static
- MONTH static
- ONE_DAY_MS static
- ONE_HOUR_MS static
- ONE_MINUTE_MS static
- ONE_SECOND_MS static
- SECONDS static
- WEEK static
- WEEK_LENGTH static
- WEEK_ONE_JAN_DATE static
- YEAR static
Methods
_absFloor
-
n
Returns the largest absolute integer less than or equal to a number.
Parameters:
-
n
Object
_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
add
-
date
-
field
-
amount
Adds the specified amount of time to the this instance.
Parameters:
Returns:
The resulting Date object
after
-
date
-
compareTo
Determines whether a given date is after another date on the calendar.
Parameters:
Returns:
true if the date occurs after the compared date; false if not.
before
-
date
-
compareTo
Determines whether a given date is before another date on the calendar.
Parameters:
Returns:
true if the date occurs before the compared date; false if not.
between
-
date
-
dateBegin
-
dateEnd
Determines whether a given date is between two other dates on the calendar.
Parameters:
Returns:
true if the date occurs between the compared dates; false if not.
clearTime
-
date
Clears the time fields from a given date, effectively setting the time to 12 noon.
Parameters:
-
date
DateThe JavaScript Date for which the time fields will be cleared
Returns:
The JavaScript Date cleared of all time fields
clone
-
date
Clones the passed date object.
Parameters:
-
date
DateThe JavaScript Date to clone
Returns:
The JavaScript Date cloned
compare
-
d1
-
d2
Compare dates.
Parameters:
Returns:
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.
Parameters:
-
d1
ObjectOne of the days
-
d2
ObjectThe other day
Returns:
the number of days between the two dates.
findMonthEnd
-
date
Gets the last day of a month containing a given date.
Parameters:
-
date
DateThe JavaScript Date used to calculate the month end
Returns:
The JavaScript Date representing the last day of the month
findMonthStart
-
date
Getss the first day of a month containing a given date.
Parameters:
-
date
DateThe JavaScript Date used to calculate the month start
Returns:
The JavaScript Date representing the first day of the month
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:
Returns:
The JavaScript date object with year, month, date set as provided.
getDayOffset
-
d1
-
d2
Calculates the number of days between the specified dates.
Returns:
The number of days
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:
Returns:
The number of days since January 1 of the given year
getDaysInMonth
-
year
-
month
Gets date from a given month and year.
Parameters:
-
year
Object -
month
Object
Returns:
getFirstDayOfWeek
-
dt
-
startOfWeek
Gets the first day of the week, for the give date.
Parameters:
Returns:
The first day of the week
getHoursOffset
-
d1
-
d2
Calculates the number of hours between the specified dates.
Returns:
The number of hours
getJan1
-
calendarYear
Retrieves a JavaScript Date object representing January 1 of any given year.
Parameters:
-
calendarYear
NumberThe calendar year for which to retrieve January 1
Returns:
January 1 of the calendar year specified.
getMinutesOffset
-
d1
-
d2
Calculates the number of minutes between the specified dates.
Returns:
The number of minutes
getOffset
-
d1
-
d2
-
constantAmount
Returns the amount of time subtracted.
Parameters:
-
d1
Object -
d2
Object -
constantAmount
Object
getSecondsOffset
-
d1
-
d2
Calculates the number of seconds between the specified dates.
Returns:
The number of seconds
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
DateThe JavaScript date for which to find the week number
-
firstDayOfWeek
NumberThe index of the first day of the week (0 = Sun, 1 = Mon ... 6 = Sat). Defaults to 0
-
janDate
NumberThe 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:
The number of the week containing the given date.
isDayBoundary
-
date1
-
date2
Checks if the {date2} is the next day at 00:00:00.
Returns:
boolean
isDayOverlap
-
date1
-
date2
Checks if the passed date is between two days.
Returns:
boolean
isMonthOverlapWeek
-
weekBeginDate
Determines if a given week overlaps two different months.
Parameters:
-
weekBeginDate
DateThe JavaScript Date representing the first day of the week.
Returns:
true if the date overlaps two different months.
isMonWedOrFri
-
date
Checks if the passed date is a Monday, Wednesday or Friday.
Parameters:
-
date
DateDate
Returns:
boolean
isNextDay
-
date1
-
date2
Checks if the {date2} is the next day.
Returns:
boolean
isSameMonth
-
d1
-
d2
Checks if the passed dates are in the same month.
Returns:
boolean
isTueOrThu
-
date
Checks if the passed date is a Tuesday or Thursday.
Parameters:
-
date
DateDate
Returns:
boolean
isWeekDay
-
date
Checks if the passed date is a week day.
Parameters:
-
date
DateDate
Returns:
boolean
isYearOverlapWeek
-
weekBeginDate
Determines if a given week overlaps two different years.
Parameters:
-
weekBeginDate
DateThe JavaScript Date representing the first day of the week.
Returns:
true if the date overlaps two different years.
safeClearTime
-
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
DateThe JavaScript Date for which the time fields will be cleared
Returns:
The JavaScript Date cleared of all time fields
subtract
-
date
-
field
-
amount
Subtracts the specified amount of time from the this instance.
Parameters:
Returns:
The resulting Date object
toIsoTimeString
-
date
-
showSeconds
Converts a date to ISO time format.
Parameters:
-
date
Object -
showSeconds
Object
Returns:
time
toLastHour
-
date
Given a date, returns a {Date} object pointing to the last moment of the day.
Parameters:
-
date
DateThe date from which it will return the last moment.
Returns:
The last moment (23:59:59:999) of the given date.
toMidnight
-
date
Given a date, returns a {Date} object pointing to the first moment of the day (i.e. the midnight of that date).
Parameters:
-
date
DateThe date from which it will return the midnight.
Returns:
The midnight of the given date.
toUsTimeString
-
date
-
padHours
-
omitMinutes
-
hideAmPm
Converts a date to US time format.
Parameters:
-
date
Object -
padHours
Object -
omitMinutes
Object -
hideAmPm
Object
Returns:
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.
SECONDS
String
final
static
Constant field representing Seconds.
WEEK
String
final
static
Constant field representing 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.