Module core/date
Adds useful methods to the JavaScript Date type.
Class Date
Instance Methods
- diff(dateObj)
- equals(Object, Int)
- format(format, locale, timezone)
- getAge(param)
- getExpiry(param)
- getTimespan(Object)
- toLocalTime()
- toUtc()
Date.prototype.diff (dateObj)
returns the difference between this and another date object in milliseconds
Parameters
| dateObj |
Date.prototype.equals (Object, Int)
checks if a date object equals another date object
Parameters
| Object | Date object to compare | |
| Int | indicating how far the comparison should go |
Returns
| Boolean |
Date.prototype.format (format, locale, timezone)
Format a Date to a string. For details on the format pattern, see http://java.sun.com/j2se/1.4.2/docs/api/java/text/SimpleDateFormat.html
Parameters
| String | format | the format pattern |
| String|java.util.Locale | locale | (optional) the locale as java Locale object or lowercase two-letter ISO-639 code (e.g. "en") |
| String|java.util.TimeZone | timezone | (optional) the timezone as java TimeZone object or an abbreviation such as "PST", a full name such as "America/Los_Angeles", or a custom ID such as "GMT-8:00". If the id is not provided, the default timezone is used. If the timezone id is provided but cannot be understood, the "GMT" timezone is used. |
Returns
| String | the formatted Date |
Date.prototype.getAge (param)
return the past timespan between this Date object and the current Date or a different Date object
Parameters
| param |
Date.prototype.getExpiry (param)
return the future timespan between this Date object and the current Date or a different Date object
Parameters
| param |
Date.prototype.getTimespan (Object)
return the timespan to current date/time or a different Date object
Parameters
| Object | parameter object containing optional properties: .now = String to use if difference is < 1 minute .day|days = String to use for single|multiple day(s) .hour|hours = String to use for single|multiple hour(s) .minute|minutes = String to use for single|multiple minute(s) .date = Date object to use for calculating the timespan |
Returns
| Object containing properties: .isFuture = (Boolean) .span = (String) timespan |
Date.prototype.toLocalTime ()
set the date/time to local time by adding the timezone offset
Date.prototype.toUtc ()
set the date/time to UTC by subtracting the timezone offset
