Packagesekati.utils
Classpublic class DateUtil

Static class for handling dates & converting them into readable strings. Note that all day & month collections are 0-indexed.



Public Properties
 PropertyDefined by
  MONTHS_SHORT : Array
[static][read-only] An array of abbreviated month.
DateUtil
  WEEKDAYS_INITIALS : Array
[static][read-only] An array of initials for the days of the week.
DateUtil
  WEEKDAYS_SHORT : Array
[static][read-only] An array of abbreviated days of the week.
DateUtil
Public Methods
 MethodDefined by
  
DateUtil Static Constructor
DateUtil
  
countDays(start:Date, end:Date):Number
[static] The number of days between the start value and the end value.
DateUtil
  
dateCeil(d:Date, timeUnit:String = "day"):Date
[static] Rounds a date up to the nearest time unit.
DateUtil
  
dateDiff(d1:Date, d2:Date = null):Number
[static] Get the differences between two Dates in milliseconds.
DateUtil
  
dateDiffDays(d1:Date, d2:Date):Number
[static] Get the difference between two Dates in days.
DateUtil
  
dateDiffMinutes(d1:Date, d2:Date):Number
[static] Get the difference between two Dates in minutes.
DateUtil
  
dateDiffSeconds(d1:Date, d2:Date):Number
[static] Get the difference between two Dates in seconds.
DateUtil
  
dateFloor(d:Date, timeUnit:String = "day"):Date
[static] Rounds a date down to the nearest time unit.
DateUtil
  
dateFromDB(dbdate:String):Date
[static] Convert a DB formatted date string into a Flash Date Object.
DateUtil
  
getHoursAmPm(hour24:int):Object
[static] Takes 24hr hours and converts to 12 hour with am/pm.
DateUtil
  
getMonthName(index:int):String
[static] Gets the name of the month specified by index.
DateUtil
  
getShortMonthName(index:int):String
[static] Gets the abbreviated month name specified by index.
DateUtil
  
getTotalDaysInMonth(year:int, month:int):int
[static] Return the number of dates in a specific month.
DateUtil
  
getTotalDaysInYear(year:int):int
[static] Returns the number of days in a specific year.
DateUtil
  
isLeapYear(year:int):Boolean
[static] Determines if the input year is a leap year (with 366 days, rather than 365).
DateUtil
  
isSameDay(d0:Date, d1:Date = null):Boolean
[static] Compare two Date's to see if they fall on the same day, month & year.
DateUtil
  
isValidAge(year:int, month:int, day:int, requiredAge:int):Boolean
[static] Check if birthdate entered meets required age.
DateUtil
  
isValidDate(year:Number, month:Number, day:Number, mustBeInPast:Boolean):Boolean
[static] Check if a valid date can be created with inputs.
DateUtil
  
isValidGregorian(d1:Date):Boolean
[static] Time values of the Date class prior to the 15th October 1582 pre-date the introduction of the modern Gregorian Calendar (used by Actionscript, JavaScript, UNIX, etc).
DateUtil
  
padTime(n:int):String
[static] Pads hours, Minutes or Seconds with a leading 0, 12:01 doesn't end up 12:1
DateUtil
  
secToFormattedTime(seconds:Number):String
[static] Convert seconds to a formatted time string.
DateUtil
  
toOrdinal(n:int):String
[static] Reformat an integer to an ordinal number (1st, 2nd, 3rd, 4th, etc).
DateUtil
  
toRelative(pastDate:Date):String
Return a human-readable relative string (yesterday, 10 minutes ago, etc) for a Date object.
DateUtil
Public Constants
 ConstantDefined by
  DAYS_IN_APRIL : int = 30
[static]
DateUtil
  DAYS_IN_AUGUST : int = 31
[static]
DateUtil
  DAYS_IN_DECEMBER : int = 31
[static]
DateUtil
  DAYS_IN_FEBRUARY : int = 28
[static]
DateUtil
  DAYS_IN_FEBRUARY_LEAP_YEAR : int = 29
[static]
DateUtil
  DAYS_IN_JANUARY : int = 31
[static]
DateUtil
  DAYS_IN_JULY : int = 31
[static]
DateUtil
  DAYS_IN_JUNE : int = 30
[static]
DateUtil
  DAYS_IN_LEAP_YEAR : int = 366
[static]
DateUtil
  DAYS_IN_MARCH : int = 31
[static]
DateUtil
  DAYS_IN_MAY : int = 31
[static]
DateUtil
  DAYS_IN_MONTHS : Array
[static]
DateUtil
  DAYS_IN_NOVEMBER : int = 30
[static]
DateUtil
  DAYS_IN_OCTOBER : int = 31
[static]
DateUtil
  DAYS_IN_SEPTEMBER : int = 30
[static]
DateUtil
  DAYS_IN_YEAR : int = 365
[static]
DateUtil
  MONTHS : Array
[static]
DateUtil
  WEEKDAYS : Array
[static]
DateUtil
Property detail
MONTHS_SHORTproperty
MONTHS_SHORT:Array  [read-only]

An array of abbreviated month. E.g. Jan, Feb, Mar, Apr, May, Jun, Jul.

Implementation
    public static function get MONTHS_SHORT():Array
WEEKDAYS_INITIALSproperty 
WEEKDAYS_INITIALS:Array  [read-only]

An array of initials for the days of the week. E.g. S, M, T, W, T, F, S.

Implementation
    public static function get WEEKDAYS_INITIALS():Array
WEEKDAYS_SHORTproperty 
WEEKDAYS_SHORT:Array  [read-only]

An array of abbreviated days of the week. E.g. Sun, Mon, Tue, Wed, Thu, Fri, Sat.

Implementation
    public static function get WEEKDAYS_SHORT():Array
Constructor detail
DateUtil()constructor
public function DateUtil()

DateUtil Static Constructor

Method detail
countDays()method
public static function countDays(start:Date, end:Date):Number

The number of days between the start value and the end value. The result may contain a fractional part, so cast it to int if a whole number is desired.

Parameters
start:Date — the starting date of the range
 
end:Date — the ending date of the range

Returns
Number — the number of days between start and end
dateCeil()method 
public static function dateCeil(d:Date, timeUnit:String = "day"):Date

Rounds a date up to the nearest time unit.

Parameters
d:Date — date to round
 
timeUnit:String (default = "day") — the time unit to round up to

Returns
Date — the the date object rounded up to
dateDiff()method 
public static function dateDiff(d1:Date, d2:Date = null):Number

Get the differences between two Dates in milliseconds.

Parameters
d1:Date
 
d2:Date (default = null)

Returns
Number — difference between two dates in ms
dateDiffDays()method 
public static function dateDiffDays(d1:Date, d2:Date):Number

Get the difference between two Dates in days.

Parameters
d1:Date
 
d2:Date

Returns
Number — difference between two dates in d
dateDiffMinutes()method 
public static function dateDiffMinutes(d1:Date, d2:Date):Number

Get the difference between two Dates in minutes.

Parameters
d1:Date
 
d2:Date

Returns
Number — difference between two dates in m
dateDiffSeconds()method 
public static function dateDiffSeconds(d1:Date, d2:Date):Number

Get the difference between two Dates in seconds.

Parameters
d1:Date
 
d2:Date

Returns
Number — difference between two dates in s
dateFloor()method 
public static function dateFloor(d:Date, timeUnit:String = "day"):Date

Rounds a date down to the nearest time unit.

Parameters
d:Date — date to round
 
timeUnit:String (default = "day") — the time unit to round down to

Returns
Date — the the date object rounded up to
dateFromDB()method 
public static function dateFromDB(dbdate:String):Date

Convert a DB formatted date string into a Flash Date Object.

Parameters
dbdate:String — date in YYYY-MM-DD HH:MM:SS or YYYY-MM-DD format.

Returns
Date
getHoursAmPm()method 
public static function getHoursAmPm(hour24:int):Object

Takes 24hr hours and converts to 12 hour with am/pm.

Parameters
hour24:int

Returns
Object
getMonthName()method 
public static function getMonthName(index:int):String

Gets the name of the month specified by index. This is the month value as stored in a Date object.

Parameters
index:int — the numeric value of the month

Returns
String — the string name of the month in English
getShortMonthName()method 
public static function getShortMonthName(index:int):String

Gets the abbreviated month name specified by index. This is the month value as stored in a Date object.

Parameters
index:int — the numeric value of the month

Returns
String — the short string name of the month in English
getTotalDaysInMonth()method 
public static function getTotalDaysInMonth(year:int, month:int):int

Return the number of dates in a specific month.

Parameters
year:int
 
month:int

Returns
int
getTotalDaysInYear()method 
public static function getTotalDaysInYear(year:int):int

Returns the number of days in a specific year.

Parameters
year:int

Returns
int
isLeapYear()method 
public static function isLeapYear(year:int):Boolean

Determines if the input year is a leap year (with 366 days, rather than 365).

Parameters
year:int — the year value as stored in a Date object.

Returns
Boolean — true if the year input is a leap year
isSameDay()method 
public static function isSameDay(d0:Date, d1:Date = null):Boolean

Compare two Date's to see if they fall on the same day, month & year.

Parameters
d0:Date — first date to compare.
 
d1:Date (default = null) — second date to compare [Optional, Default: today].

Returns
Boolean — Boolean value denoting whether the date is the same (true) or not (false).
isValidAge()method 
public static function isValidAge(year:int, month:int, day:int, requiredAge:int):Boolean

Check if birthdate entered meets required age.

Parameters
year:int
 
month:int
 
day:int
 
requiredAge:int

Returns
Boolean
isValidDate()method 
public static function isValidDate(year:Number, month:Number, day:Number, mustBeInPast:Boolean):Boolean

Check if a valid date can be created with inputs.

Parameters
year:Number
 
month:Number
 
day:Number
 
mustBeInPast:Boolean

Returns
Boolean
isValidGregorian()method 
public static function isValidGregorian(d1:Date):Boolean

Time values of the Date class prior to the 15th October 1582 pre-date the introduction of the modern Gregorian Calendar (used by Actionscript, JavaScript, UNIX, etc).

Parameters
d1:Date

Returns
Boolean
padTime()method 
public static function padTime(n:int):String

Pads hours, Minutes or Seconds with a leading 0, 12:01 doesn't end up 12:1

Parameters
n:int

Returns
String
secToFormattedTime()method 
public static function secToFormattedTime(seconds:Number):String

Convert seconds to a formatted time string.

Parameters
seconds:Number

Returns
String
toOrdinal()method 
public static function toOrdinal(n:int):String

Reformat an integer to an ordinal number (1st, 2nd, 3rd, 4th, etc).

Parameters
n:int

Returns
String
toRelative()method 
public function toRelative(pastDate:Date):String

Return a human-readable relative string (yesterday, 10 minutes ago, etc) for a Date object.

Parameters
pastDate:Date — a Date object older that the current Date.

Returns
String — human readable descriptive string relative to the current date.
Constant detail
DAYS_IN_APRILconstant
public static const DAYS_IN_APRIL:int = 30
DAYS_IN_AUGUSTconstant 
public static const DAYS_IN_AUGUST:int = 31
DAYS_IN_DECEMBERconstant 
public static const DAYS_IN_DECEMBER:int = 31
DAYS_IN_FEBRUARYconstant 
public static const DAYS_IN_FEBRUARY:int = 28
DAYS_IN_FEBRUARY_LEAP_YEARconstant 
public static const DAYS_IN_FEBRUARY_LEAP_YEAR:int = 29
DAYS_IN_JANUARYconstant 
public static const DAYS_IN_JANUARY:int = 31
DAYS_IN_JULYconstant 
public static const DAYS_IN_JULY:int = 31
DAYS_IN_JUNEconstant 
public static const DAYS_IN_JUNE:int = 30
DAYS_IN_LEAP_YEARconstant 
public static const DAYS_IN_LEAP_YEAR:int = 366
DAYS_IN_MARCHconstant 
public static const DAYS_IN_MARCH:int = 31
DAYS_IN_MAYconstant 
public static const DAYS_IN_MAY:int = 31
DAYS_IN_MONTHSconstant 
public static const DAYS_IN_MONTHS:Array
DAYS_IN_NOVEMBERconstant 
public static const DAYS_IN_NOVEMBER:int = 30
DAYS_IN_OCTOBERconstant 
public static const DAYS_IN_OCTOBER:int = 31
DAYS_IN_SEPTEMBERconstant 
public static const DAYS_IN_SEPTEMBER:int = 30
DAYS_IN_YEARconstant 
public static const DAYS_IN_YEAR:int = 365
MONTHSconstant 
public static const MONTHS:Array
WEEKDAYSconstant 
public static const WEEKDAYS:Array