Date/Time Library
The functions in this library provide support for dates, times, and calendars.
N.B.: This library and related date and time functionality in Dallycot is experimental and subject to change.
Functions
calendar-convert
(datetime: DateTime, calendar: String = “Gregorian”) → DateTime
Converts a date and time from one calendar to another. Acceptable calendars are those supported by the date
function.
Examples
calendar-convert(date(<2015,5,30>), "Mayan") = 13.0.2.8.10
calendar-convert(date(<1>, calendar -> "Islamic"), "Gregorian") = 0622-07-19T00:00:00
calendar-convert(date(<1>, calendar -> "Islamic"), "Julian") = 0622-07-16J00:00:00
calendar-convert(date(<632,3,6>, calendar -> "Julian", timezone -> "+0300"), "Islamic") = 10-12-7 AH
Implementation
This is implemented internally.
date
(vector: <Numeric>, calendar -> “Gregorian”, timezone -> “UTC”) → DateTime
Creates a date/time object representing the given date on the given calendar.
The following calendars are available with the given values in the numeric vector.
Calendar | Vector | Timezones |
Gregorian | year, month, day, hour, minute, second | Yes |
Hebrew | year, month, day | Yes |
Hijri | year, month, day | No |
Islamic | year, month, day | No |
Jewish | year, month, day | Yes |
Julian | year, month, day, hour, minute, second | Yes |
Mayan | baktun, katun, tun, uinal, kin | No |
Pataphysical | year, month, day | No |
Examples
date(<2015, 5, 10>) = 2015-05-10T00:00:00
date(<13,0,0,0,0>, calendar -> "Mayan") = 13.0.0.0.0
Implementation
This is implemented internally using DateTime.
duration
(<Numeric>|DateTime, [DateTime]) → Duration
Creates a duration object representing the given length of time. The vector represents the number of years, months, days, hours, minutes, and seconds, respectively, in the duration.
If two arguments are provided, both must be dates and the duration will be the amount of time that must be added to the first to equal the second.
Examples
duration(<1, 15>) = P2Y3M
duration(date(<2014,1,1>), date(<2015,1,1>)) = P1Y
duration(<0,0,0,0,0,55>) + duration(<0,0,0,0,0,10>) = PT65S
Implementation
This is implemented internally.
convert-timezone
(datetime: DateTime, timezone: String) → DateTime
Converts a date/time object from one timezone to another.
Examples
convert-timezone(date(<2014,1,23,1,30>, timezone -> "UTC"), "EST") = 2014-01-22T20:30:00
now
(timezone -> “UTC”) → DateTime
Returns the current date and time in the given time zone.
Examples
now(timezone -> "UTC") = 2015-05-10T23:48:15
now(timezone -> "EST") = 2015-05-10T18:48:15
Implementation
This is implemented internally using DateTime.
parse-datetime
(datetime: String, language ->
Parses a string describing a date and time. By default, the language is that attached to the string.
Examples
parse-datetime("1 year ago") = 2014-05-10T00:22:44
parse-datetime("hace 3 años"@es) = 2012-05-11T00:27:37
parse-datetime("2015010203040506") = 2015-01-02T03:04:05
Implementation
This is implemented internally using DateTime::Format::Flexible.