SimileAjax/DateTime

= SimileAjax.DateTime =

Utilities for dealing with dates, times, and time zones, with a focus on ISO8601 date representation.

Code: http://api.simile-widgets.org/ajax/2.2.1/scripts/date-time.js

Migration Notes
The only functions used from here relate to parsing ISO-8601 strings to native Javascript Date objects. They should be the only ones to move.

Back to SimileAjax.

Constants
These are all mapped to integer values, they are provided as labelled indices to SimileAjax.DateTime.gregorianUnitLengths. See the source for actual values, but don't really look.


 * SimileAjax.DateTime.MILLISECOND
 * SimileAjax.DateTime.SECOND
 * SimileAjax.DateTime.MINUTE
 * SimileAjax.DateTime.HOUR
 * SimileAjax.DateTime.DAY
 * SimileAjax.DateTime.WEEK
 * SimileAjax.DateTime.MONTH
 * SimileAjax.DateTime.YEAR
 * SimileAjax.DateTime.DECADE
 * SimileAjax.DateTime.CENTURY
 * SimileAjax.DateTime.MILLENNIUM
 * SimileAjax.DateTime.EPOCH
 * SimileAjax.DateTime.ERA

SimileAjax.DateTime.gregorianUnitLengths

 * Type: Array
 * Default: See source
 * Description: An array of unit lengths, expressed in milliseconds, of various lengths of time. The array indices are predefined and stored as properties of the SimileAjax.DateTime object, e.g. SimileAjax.DateTime.YEAR.

SimileAjax.DateTime._dateRegexp

 * Type: RegExp
 * Default: See source
 * Description: Constant, matches the date portion of the ISO-8601 format

SimileAjax.DateTime._timezoneRegexp

 * Type: RegExp
 * Default: See source
 * Description: Constant, matches the timezone portion of the ISO-8601 format

SimileAjax.DateTime._timeRegexp

 * Type: RegExp
 * Default: See source
 * Description: Constant, matches the time portion of the ISO-8601 format

SimileAjax.DateTime.setIso8601Date

 * Arguments:
 * dateObject: Date, the date object to modify
 * string: string, the ISO-8601 formatted text
 * Returns: Date, the modified date object
 * Description: Takes a date object and a string containing an ISO 8601 date and sets the the date using information parsed from the string. Note that this method does not parse any time information.

SimileAjax.DateTime.setIso8601Time

 * Arguments:
 * dateObject: Date, the date object to modify
 * string: string, the ISO-8601 formatted text
 * Returns: Date, the modified date object
 * Description: Takes a date object and a string containing an ISO 8601 time and sets the the time using information parsed from the string. Note that this method does not parse any date information.

SimileAjax.DateTime.timezoneOffset

 * Arguments: None
 * Returns: int, offset in minutes
 * Description: The timezone offset in minutes in the user's browser.

SimileAjax.DateTime.setIso8601

 * Arguments:
 * dateObject: Date, a native Date object
 * string: string, an ISO-8601 formatted string
 * Returns: Date, the modified object
 * Description: Takes a date object and a string containing an ISO 8601 date and time and sets the date object using information parsed from the string.

SimileAjax.DateTime.parseIso8601DateTime

 * Arguments:
 * string: string, a date written out as ISO-8601 formatted text
 * Returns: Date
 * Description: Parses a string in ISO-8601 format into a native Javascript Date object

SimileAjax.DateTime.parseGregorianDateTime

 * Arguments:
 * o, string or Date, string to be parsed into a date or Date to be returned immediately
 * Returns: Date, the date object
 * Description: Takes a string containing a Gregorian date and time and returns a newly instantiated date object with the parsed date and time information from the string. If the param is actually an instance of Date instead of a string, simply returns the given date instead.

SimileAjax.DateTime.roundDownToInterval

 * Arguments:
 * date: Date, the date object to round
 * intervalUnit: a constant, integer index specifying an interval, e.g. SimileAjax.DateTime.HOUR
 * timeZone: number, a timezone shift, given in hours
 * multiple: number, a multiple of the interval to round by
 * firstDayOfWeek: int, first day of the week where 0 is Sunday, 1 is Monday, etc.
 * Returns: Nothing
 * Description: Rounds date objects down to the nearest interval or multiple of an interval. This method modifies the given date object, converting it to the given timezone if specified.

SimileAjax.DateTime.roundUpToInterval

 * Arguments:
 * date: Date, the date object to round
 * intervalUnit: a constant, integer index specifying an interval, e.g. SimileAjax.DateTime.HOUR
 * timeZone: number, a timezone shift, given in hours
 * multiple: number, a multiple of the interval to round by
 * firstDayOfWeek: int, first day of the week where 0 is Sunday, 1 is Monday, etc.
 * Returns: Nothing
 * Description: Rounds date objects up to the nearest interval or multiple of an interval. This method modifies the given date object, converting it to the given timezone if specified.

SimileAjax.DateTime.incrementByInterval

 * Arguments:
 * date: Date, the date object to round
 * intervalUnit: a constant, integer index specifying an interval, e.g. SimileAjax.DateTime.HOUR
 * timeZone: number, a timezone shift, given in hours
 * Returns: Nothing
 * Description: Increments a date object by a specified interval, taking into consideration the timezone.

SimileAjax.DateTime.remoteTimeZoneOffset

 * Arguments:
 * date: Date, the starting date
 * timeZone: number, a timezone specified in an hour offset to remove
 * Returns: Date, a new date object with the given time offset removed
 * Description: Returns a new date object with the given time offset removed.

SimileAjax.DateTime.getTimezone

 * Arguments: None
 * Returns: number, the timezone in the user's locale in hours
 * Description: Returns the timezone of the user's browser.

Back to SimileAjax.