Packagexp.utils
Classpublic class DateTimeUtils



Public Methods
 MethodDefined by
  
addDays(date1:Date, days:Number):Date
[static] Adds days to the date date1
DateTimeUtils
  
ceil(time:Number, resolution:Number):Number
[static] Limit a date's resolution.
DateTimeUtils
  
dateCopy(date1:Date):Date
[static] Clones a date object
DateTimeUtils
  
dateDiff(date1:Object, date2:Object, unit:int):Number
[static] Calculate the difference between two dates Note that difference between simply taking the difference between two date objects and dividing by the unit of time.
DateTimeUtils
  
dateEqual(date1:Date, date2:Date, unit:int):Boolean
[static] Compares two dates and return true if they are within the same unit of time
DateTimeUtils
  
floor(time:Number, resolution:Number):Number
[static] Limit a date's resolution.
DateTimeUtils
  
getDate(y:Number, m:Number, d:Number):Date
[static] Returns a date object for the specified year/month and day, if any value is not set default to now
DateTimeUtils
  
getDateTimeUnit(interval:int):int
[static] Given an interval between two dates determine the unit of time
DateTimeUtils
  
getDayInYear(day:int, month:int, year:int):int
[static] Calculates the day in a year
DateTimeUtils
  
getFieldChangeLevel(date1:Object, date2:Object):int
[static] Detects which field changed between two dates Example: 2007,2,1` and 2006,2,20 would return YEAR Example: 2007,1,1,0,0,0,0` and 2006,11,31,23,59,999 would also return YEAR This would then indicate all fields below that level are invalid
DateTimeUtils
  
getJan1DayOfWeek(year:int):int
[static] Get the day of week of Jan 1 of the given year
DateTimeUtils
  
getNumberOfDaysInMonth(year:Number, month:Number):Number
[static] Returns the number of days in a month
DateTimeUtils
  
getQuarterInYear(date:Object):int
[static] Calculates the number of the quarter in ther year
DateTimeUtils
  
getStartOfMonth(year:Number, month:Number):Number
[static] Finds the day of week of the first day of the month
DateTimeUtils
  
getStartOfMonthAsTime(year:Number, month:Number):Number
[static] Finds the time(ms from epoch) of the first day of the month
DateTimeUtils
  
[static] Gets the timezone offset from UTC
DateTimeUtils
  
getWeekNumber(day:int, year:int, firstWeekDays:int):int
[static] Calculates the week number for a day in a year
DateTimeUtils
  
isLeapYear(year:int):Boolean
[static] Calculates if the given year is a leapyear or not
DateTimeUtils
Public Constants
 ConstantDefined by
  DAY : int = 4
[static]
DateTimeUtils
  defaultDayNames : Array
[static]
DateTimeUtils
  defaultMonthNames : Array
[static]
DateTimeUtils
  fields : Array
[static]
DateTimeUtils
  HOUR : int = 3
[static]
DateTimeUtils
  MILLISECOND : int = 0
[static]
DateTimeUtils
  MINUTE : int = 2
[static]
DateTimeUtils
  MONTH : int = 6
[static]
DateTimeUtils
  ms : Array
[static]
DateTimeUtils
  MSDAY : Number = 8.64E7
[static]
DateTimeUtils
  MSHOUR : Number = 3600000.0
[static]
DateTimeUtils
  MSMILLISECOND : Number = 1
[static]
DateTimeUtils
  MSMINUTE : Number = 60000.0
[static]
DateTimeUtils
  MSMONTH : Number = 2.4192E9
[static]
DateTimeUtils
  MSQUARTER : Number = 7.2576E9
[static]
DateTimeUtils
  MSSECOND : Number = 1000
[static]
DateTimeUtils
  MSWEEK : Number = 6.048E8
[static]
DateTimeUtils
  MSYEAR : Number = 3.1536E10
[static]
DateTimeUtils
  QUARTER : int = 7
[static]
DateTimeUtils
  SECOND : int = 1
[static]
DateTimeUtils
  units : Array
[static]
DateTimeUtils
  WEEK : int = 5
[static]
DateTimeUtils
  YEAR : int = 8
[static]
DateTimeUtils
Method detail
addDays()method
public static function addDays(date1:Date, days:Number):Date

Adds days to the date date1

Parameters
date1:Date
 
days:Number

Returns
Date
ceil()method 
public static function ceil(time:Number, resolution:Number):Number

Limit a date's resolution. For example, the date 1095767411000 (which represents 2004-09-21 13:50:11) will be changed to 1093989600000 (2004-10-01 00:00:00) when using MONTH.

Parameters
time:Number — The time in miliseconds
 
resolution:Number — The desired resolution of the date to be returned

Returns
Number — the date with all values more precise than resolution set to 0 or 1, expressed as milliseconds since January 1, 1970, 00:00:00 GMT
dateCopy()method 
public static function dateCopy(date1:Date):Date

Clones a date object

Parameters
date1:Date

Returns
Date
dateDiff()method 
public static function dateDiff(date1:Object, date2:Object, unit:int):Number

Calculate the difference between two dates Note that difference between simply taking the difference between two date objects and dividing by the unit of time. If we compared 10 minutes to midnight and 10 minutes after midnight the simple approach would give the difference as 0 days as the difference is only 20 minutes. The dateDif function however would return 1 day as the two dates are on different days.

Parameters
date1:Object — The starting date
 
date2:Object — The ending date
 
unit:int — The unit of time to measure. One of the DateUtils date/time constants QUARTER/WEEK/DAY/HOUR/MINUTE/SECOND

Returns
Number — The difference in units as specified by interval
dateEqual()method 
public static function dateEqual(date1:Date, date2:Date, unit:int):Boolean

Compares two dates and return true if they are within the same unit of time

Parameters
date1:Date
 
date2:Date
 
unit:int — unit the unit of time to measure defaults to day

Returns
Boolean — True if the are within the same unit of time
floor()method 
public static function floor(time:Number, resolution:Number):Number

Limit a date's resolution. For example, the date 1095767411000 (which represents 2004-09-21 13:50:11) will be changed to 1093989600000 (2004-09-01 00:00:00) when using MONTH.

Parameters
time:Number — The time in miliseconds
 
resolution:Number — The desired resolution of the date to be returned

Returns
Number — the date with all values more precise than resolution set to 0 or 1, expressed as milliseconds since January 1, 1970, 00:00:00 GMT
getDate()method 
public static function getDate(y:Number, m:Number, d:Number):Date

Returns a date object for the specified year/month and day, if any value is not set default to now

Parameters
y:Number
 
m:Number
 
d:Number

Returns
Date — The date object as specified
getDateTimeUnit()method 
public static function getDateTimeUnit(interval:int):int

Given an interval between two dates determine the unit of time

Parameters
interval:int

Returns
int — the unit of time the interval represents

See also

dateDiff
getDayInYear()method 
public static function getDayInYear(day:int, month:int, year:int):int

Calculates the day in a year

Parameters
day:int — The day in month
 
month:int — month
 
year:int — full year

Returns
int — the day in year
getFieldChangeLevel()method 
public static function getFieldChangeLevel(date1:Object, date2:Object):int

Detects which field changed between two dates Example: 2007,2,1` and 2006,2,20 would return YEAR Example: 2007,1,1,0,0,0,0` and 2006,11,31,23,59,999 would also return YEAR This would then indicate all fields below that level are invalid

Parameters
date1:Object
 
date2:Object

Returns
int — The top most field that changed
getJan1DayOfWeek()method 
public static function getJan1DayOfWeek(year:int):int

Get the day of week of Jan 1 of the given year

Parameters
year:int — the full year

Returns
int
getNumberOfDaysInMonth()method 
public static function getNumberOfDaysInMonth(year:Number, month:Number):Number

Returns the number of days in a month

Parameters
year:Number
 
month:Number

Returns
Number — The number of days in the given month
getQuarterInYear()method 
public static function getQuarterInYear(date:Object):int

Calculates the number of the quarter in ther year

Parameters
date:Object — The time in millisecodns or a Date object

Returns
int — The quarter
getStartOfMonth()method 
public static function getStartOfMonth(year:Number, month:Number):Number

Finds the day of week of the first day of the month

Parameters
year:Number — The target year to check
 
month:Number — The target month to check

Returns
Number — The number of the day of week
getStartOfMonthAsTime()method 
public static function getStartOfMonthAsTime(year:Number, month:Number):Number

Finds the time(ms from epoch) of the first day of the month

Parameters
year:Number — The target year to check
 
month:Number — The target month to check

Returns
Number — The time in ms since the epoch
getTimezoneOffset()method 
public static function getTimezoneOffset():Number

Gets the timezone offset from UTC

Returns
Number
getWeekNumber()method 
public static function getWeekNumber(day:int, year:int, firstWeekDays:int):int

Calculates the week number for a day in a year

Parameters
day:int — day in year
 
year:int — the full year
 
firstWeekDays:int — the minimum number of days allowed in the first week

Returns
int — the week number
isLeapYear()method 
public static function isLeapYear(year:int):Boolean

Calculates if the given year is a leapyear or not

Parameters
year:int

Returns
Boolean
Constant detail
DAYconstant
public static const DAY:int = 4
defaultDayNamesconstant 
public static const defaultDayNames:Array
defaultMonthNamesconstant 
public static const defaultMonthNames:Array
fieldsconstant 
public static const fields:Array
HOURconstant 
public static const HOUR:int = 3
MILLISECONDconstant 
public static const MILLISECOND:int = 0
MINUTEconstant 
public static const MINUTE:int = 2
MONTHconstant 
public static const MONTH:int = 6
msconstant 
public static const ms:Array
MSDAYconstant 
public static const MSDAY:Number = 8.64E7
MSHOURconstant 
public static const MSHOUR:Number = 3600000.0
MSMILLISECONDconstant 
public static const MSMILLISECOND:Number = 1
MSMINUTEconstant 
public static const MSMINUTE:Number = 60000.0
MSMONTHconstant 
public static const MSMONTH:Number = 2.4192E9
MSQUARTERconstant 
public static const MSQUARTER:Number = 7.2576E9
MSSECONDconstant 
public static const MSSECOND:Number = 1000
MSWEEKconstant 
public static const MSWEEK:Number = 6.048E8
MSYEARconstant 
public static const MSYEAR:Number = 3.1536E10
QUARTERconstant 
public static const QUARTER:int = 7
SECONDconstant 
public static const SECOND:int = 1
unitsconstant 
public static const units:Array
WEEKconstant 
public static const WEEK:int = 5
YEARconstant 
public static const YEAR:int = 8