Time
Functions
Returns a new time which is at the beginning of the same day as the given time.
Time.atBeginningOfDay(Time.utc(2017, 5, 20, 10, 34, 22, 40)) ==
Time.utc(2017, 5, 20, 0, 0, 0, 0)
Returns a new time which is at the beginning of the same month as the given time.
Time.atBeginningOfMonth(Time.utcDate(2017, 5, 20)) == Time.utcDate(2017, 5, 1)
Returns a new time which is at the beginning of the same week as the given time.
Time.atBeginningOfWeek(Time.utcDate(2017, 5, 20)) == Time.utcDate(2017, 5, 15)
Returns a new time which is at the beginning of the same year as the given time.
Time.atBeginningOfYear(Time.utcDate(2017, 5, 20)) == Time.utcDate(2017, 1, 1)
Returns a new time which is at the beginning of the same day as the given time.
Time.atEndOfDay(Time.utc(2017, 5, 20, 10, 34, 22, 40)) ==
Time.utc(2017, 5, 20, 0, 0, 0, 0)
Returns a new time which is at the end of the same month as the given time.
Time.atEndOfMonth(Time.utcDate(2017, 5, 20)) == Time.utcDate(2017, 5, 31)
Returns a new time which is at the beginning of the same week as the given time.
Time.atEndOfWeek(Time.utcDate(2017, 5, 20)) == Time.utcDate(2017, 5, 1)
Returns a new time which is at the end of the same year as the given time.
Time.atEndOfYear(Time.utcDate(2017, 5, 20)) == Time.utcDate(2017, 12, 31)
Returns the ISO calendar year and week of the given time.
The ISO calendar year to which the week belongs is not always in the same as the year of the regular calendar date. The first three days of January sometimes belong to week 52 (or 53) of the previous year; equally the last three days of December sometimes are already in week 1 of the following year.
For that reason, this method returns a tuple year, week
consisting of the
calendar year to which the calendar week belongs and the ordinal number of
the week within that year.
Time.calendarWeek(Time.utcDate(2016, 1, 1)) == {2016, 53}
Returns the day of month of the given time.
Time.dayOfMonth(Time.utcDate(2018, 4, 5)) == 5
Returns the day of week of the given time.
Time.dayOfWeek(Time.utcDate(2018, 4, 5)) == Weekday::Thursday
Returns the day of the week of the given time (as a number from 1 to 7).
Time.dayOfWeekNumber(Time.utcDate(2018, 4, 5)) == 4
Returns the day of the year of the given time.
Time.dayOfYear(Time.utcDate(2018, 4, 5)) == 95
Reports the approximate distance in time between two Time
objects as seconds
in the given language.
now =
Time.utc(2016, 1, 2, 12, 34, 50, 200)
time =
Time.shift(Time.Span::Hours(4), time)
Time.distanceOfTimeInWords(time, now, Time.Format::English)) == "in 4 hours"
Formats the given time using the given pattern in the given language.
Time.format(
Time.utcDate(2018, 4, 5),
Time.Format:ENGLISH,
"%Y-%m-%dT%H:%M:%S.%LZ") == "2018-04-05T00:00:00.000Z"
The following token can be used in the pattern:
- %a: short day name (Sun, Mon, Tue, ...)
- %^a: short day name, upcase (SUN, MON, TUE, ...)
- %A: day name (Sunday, Monday, Tuesday, ...)
- %^A: day name, upcase (SUNDAY, MONDAY, TUESDAY, ...)
- %b: short month name (Jan, Feb, Mar, ...)
- %^b: short month name, upcase (JAN, FEB, MAR, ...)
- %B: month name (January, February, March, ...)
- %^B: month name, upcase (JANUARY, FEBRUARY, MARCH, ...)
- %c: date and time (Tue Apr 5 10:26:19 2016)
- %C: year divided by 100
- %d: day of month, zero padded (01, 02, ...)
- %-d: day of month (1, 2, ..., 31)
- %D: date (04/05/16)
- %e: day of month, blank padded (" 1", " 2", ..., "10", "11", ...)
- %F: ISO 8601 date (2016-04-05)
- %g: week-based calendar year modulo 100 (00..99)
- %G: week-based calendar year (0001..9999)
- %h: (same as %b) short month name (Jan, Feb, Mar, ...)
- %H: hour of the day, 24-hour clock, zero padded (00, 01, ..., 24)
- %I: hour of the day, 12-hour clock, zero padded (00, 01, ..., 12)
- %j: day of year, zero padded (001, 002, ..., 365)
- %k: hour of the day, 24-hour clock, blank padded (" 0", " 1", ..., "24")
- %l: hour of the day, 12-hour clock, blank padded (" 0", " 1", ..., "12")
- %L: milliseconds, zero padded (000, 001, ..., 999)
- %m: month number, zero padded (01, 02, ..., 12)
- %_m: month number, blank padded (" 1", " 2", ..., "12")
- %-m: month number (1, 2, ..., 12)
- %M: minute, zero padded (00, 01, 02, ..., 59)
- %p: am-pm (lowercase)
- %P: AM-PM (uppercase)
- %r: 12-hour time (03:04:05 AM)
- %R: 24-hour time (13:04)
- %s: seconds since unix epoch
- %S: seconds, zero padded (00, 01, ..., 59)
- %T: 24-hour time (13:04:05)
- %u: day of week (Monday is 1, 1..7)
- %V: ISO calendar week number of the week-based year (01..53)
- %w: day of week (Sunday is 0, 0..6)
- %x: (same as %D) date (04/05/16)
- %X: (same as %T) 24-hour time (13:04:05)
- %y: year modulo 100
- %Y: year, zero padded
Formats the given time to the ISO format.
Time.formatISO(Time.utcDate(2018, 4, 5)) == "2018-04-05T00:00:00.000Z"
Formats the given time by the given single token using the given language.
Time.formatToken(Time.Format:ENGLISH, "Y", Time.utcDate(2018, 4, 5)) == "2018"
Returns the hour of the given time.
Time.hour(Time.utc(2018, 4, 5, 10, 25, 30, 40) == 10
Converts the given time zone, since not all browsers support time zone conversion this function can fail.
Time.inZone("America/New_York", Time.utc(2019, 1, 1, 7, 12, 35, 200)) ==
Maybe::Just(Time.utc(2019, 1, 1, 2, 12, 35, 200))
Returns if the year of the given time is a leap year or not.
Time.isLeapYear(Time.utcDate(2011,1,1)) == false
Time.isLeapYear(Time.utcDate(2012,1,1)) == true
Returns if the given number (year) is a leap year or not.
Time.isNumberLeapYear(2020) == true
Time.isNumberLeapYear(2021) == false
Returns the current time (offset by the clients time zone).
Time.local()
Returns the millisecond of the given time.
Time.millisecond(Time.utc(2018, 4, 5, 10, 25, 30, 40)) == 40
Returns the minute of the given time.
Time.minute(Time.utc(2018, 4, 5, 10, 25, 30, 40)) == 25
Returns the month of the given time (as a Month
).
Time.month(Time.utcDate(2018, 4, 5)) == Month::April
Returns the month of the given time (as a number).
Time.monthNumber(Time.utcDate(2018, 4, 5)) == 4
Returns a new time which is a day later than the the given time.
Time.nextDay(Time.utcDate(2017, 5, 20)) == Time.utcDate(2017, 5, 21)
Returns a new time which is a month later than the the given time.
Time.nextMonth(Time.utcDate(2017, 5, 20)) == Time.utcDate(2017, 6, 20)
Returns a new time which is a week later than the the given time.
Time.nextWeek(Time.utcDate(2017, 5, 10)) == Time.utcDate(2017, 5, 17)
Returns the current time (in UTC).
Time.now()
Tries to parse the given string as an ISO date.
Time.parseISO("2018-04-05T00:00:00.000Z")
Returns a new time which is a day sooner than the the given time.
Time.previousDay(Time.utcDate(2017, 5, 20)) == Time.utcDate(2017, 5, 19)
Returns a new time which is a month sooner than the the given time.
Time.previousMonth(Time.utcDate(2017, 5, 20)) == Time.utcDate(2017, 4, 20)
Returns a new time which is a week sooner than the the given time.
Time.previousWeek(Time.utcDate(2017, 5, 20)) == Time.utcDate(2017, 5, 13)
Returns the quarter of the year in which the given time occurs.
Time.quarterOfYear(Time.utcDate(2018, 4, 5)) == 1
Returns an array of days from the given start to given end time (inclusive).
Time.range(Time.utcDate(2006, 4, 1), Time.utcDate(2006, 4, 4)) == [
Time.utcDate(2006, 4, 1),
Time.utcDate(2006, 4, 2),
Time.utcDate(2006, 4, 3),
Time.utcDate(2006, 4, 4)
]
Returns the second of the given time.
Time.second(Time.utc(2018, 4, 5, 10, 25, 30, 40)) == 30
Shifts the given time using the given time span.
Time.shift(Time.utcDate(2018, 4, 5), Time.Span::Days(2)) ==
Time.utcDate(2018, 4, 7)
Returns the UNIX Timestamp (in milliseconds) of the given time.
Time.toUnix(Time.utcDate(2006, 1, 2)) == 1136160000000
Returns the time at the begging of today.
Time.today()
Returns the time at the begging of tomorrow.
Time.tomorrow()
Returns the time respective to the given UNIX Timestamp (in milliseconds).
Time.unix(1136160000000) == Time.utcDate(2006, 1, 2)
Returns a new time from the given parameters.
Time.utc(2018, 4, 5, 12, 24, 50, 100)
Returns a new time from the given parameters (without time parts).
Time.utcDate(2018, 4, 5)
Returns the year of the given time.
Time.year(Time.utcDate(2018, 4, 5)) == 2018
Returns the time at the begging of yesterday.
Time.yesterday()