Time Functions
AsTimezone
returns time in specified timezone location
Syntax:
AsTimezone(t: time, location: string) -> time?
Examples:
AsTimezone(ParseTime("2020-01-01T00:00:00Z"), "America/New_York") = ParseTime("2019-12-31T19:00:00-05:00")
AsTimezone(ParseTime("2020-01-01T00:00:00Z"), "America/Chicago") = ParseTime("2019-12-31T18:00:00-06:00")
Day
returns day of month as number for time in UTC
Syntax:
Day(t: time) -> int
Examples:
Day(ParseTime("2001-03-19T13:52:06Z")) = 19
Days
converts duration in nanoseconds to days
Syntax:
Days(nanos: int) -> float
Examples:
Days(1 week) = 7
Days(12 hours) = 0.5
Days(ParseTime("2020-02-24T12:00:00Z")-ParseTime("2020-02-14T00:00:00Z")) = 10.5
FormatTime
returns string representation of time in optional specified layout
Syntax:
FormatTime(t: time, <layout: string>) -> string
Examples:
FormatTime(FromUnixNanos(1000)) = "1970-01-01T00:00:00.000001Z"
FormatTime(FromUnixNanos(1000), "Mon Jan 2 15:04:05 -0700 MST 2006") = "Thu Jan 1 00:00:00 +0000 UTC 1970"
FormatTime(FromUnixNanos(1000), "2006-01-02") = "1970-01-01"
FromUnixMillis
returns time, given milliseconds since epoch
Syntax:
FromUnixMillis(millis: int) -> time
Examples:
FromUnixMillis(1) = ParseTime("1970-01-01T00:00:00.001Z")
FromUnixMillis(1577836800000) = ParseTime("2020-01-01T00:00:00Z")
FromUnixNanos
returns time, given nanoseconds since epoch
Syntax:
FromUnixNanos(nanos: int) -> time
Examples:
FromUnixNanos(0) = ParseTime("1970-01-01T00:00:00Z")
FromUnixNanos(1577836800000000000) = ParseTime("2020-01-01T00:00:00Z")
FromUnixSeconds
returns time, given seconds since epoch
Syntax:
FromUnixSeconds(seconds: int) -> time
Examples:
FromUnixSeconds(1) = ParseTime("1970-01-01T00:00:01Z")
FromUnixSeconds(1577836800) = ParseTime("2020-01-01T00:00:00Z")
Hour
returns hour of day as number (0-23) for time in UTC
Syntax:
Hour(t: time) -> int
Examples:
Hour(ParseTime("2001-03-19T13:52:06Z")) = 13
Hours
converts duration in nanoseconds to hours
Syntax:
Hours(nanos: int) -> float
Examples:
Hours(1 week) = 168
Hours(15 minutes) = 0.25
Hours(ParseTime("2020-02-24T12:30:00Z")-ParseTime("2020-02-24T09:00:00Z")) = 3.5
Microsecond
return microsecond within the second as number (0-999999) for time in UTC
Syntax:
Microsecond(t: time) -> int
Examples:
Microsecond(ParseTime("2001-03-19T13:52:06.123456Z")) = 123456
Microseconds
converts duration in nanoseconds to milliseconds
Syntax:
Microseconds(nanos: int) -> float
Examples:
Microseconds(0.5 minutes) = 30000000
Microseconds(7.5 seconds) = 7500000
Microseconds(ParseTime("2020-02-24T12:00:00.234567Z")-ParseTime("2020-02-24T12:00:00Z")) = 234567
Millisecond
Syntax:
Millisecond(t: time) -> int
Examples:
Millisecond(ParseTime("2001-03-19T13:52:06.123Z")) = 123
Milliseconds
converts duration in nanoseconds to milliseconds
Syntax:
Milliseconds(nanos: int) -> float
Examples:
Milliseconds(0.5 minutes) = 30000
Milliseconds(7.5 seconds) = 7500
Milliseconds(ParseTime("2020-02-24T12:00:00.234Z")-ParseTime("2020-02-24T12:00:00Z")) = 234
Minute
returns minute within the hour as number (0-59) for time in UTC
Syntax:
Minute(t: time) -> int
Examples:
Minute(ParseTime("2001-03-19T13:52:06Z")) = 52
Minutes
converts duration in nanoseconds to minutes
Syntax:
Minutes(nanos: int) -> float
Examples:
Minutes(1 hour) = 60
Minutes(15 seconds) = 0.25
Minutes(ParseTime("2020-02-24T12:12:30Z")-ParseTime("2020-02-24T12:00:00Z")) = 12.5
Month
returns month as number (1-12) for time in UTC
Syntax:
Month(t: time) -> int
Examples:
Month(ParseTime("2001-03-19T13:52:06Z")) = 3
Nanosecond
returns nanosecond within the second as number (0-999999999) for time in UTC
Syntax:
Nanosecond(t: time) -> int
Examples:
Nanosecond(ParseTime("2001-01-01T12:13:14.123456789Z")) = 123456789
ParseTime
parses text to retrieve time in optional specified layout
Syntax:
ParseTime(text: string, <layout: string>) -> time?
Examples:
ParseTime("1970-01-01T00:00:00Z") = FromUnixNanos(0)
ParseTime("2020-07-31T19:00:00-05:00") = ParseTime("2020-08-01T00:00:00Z")
ParseTimeLayout
parses time text to retrieve layout
Syntax:
ParseTimeLayout(text: string) -> string?
Examples:
ParseTimeLayout("2011-06-26") = "2006-01-02"
ParseTimeLayout(FormatTime(EventTime(), "Jan 02, 2006 3:04PM")) = "Jan 02, 2006 3:04PM"
Second
return second within the minute as number (0-59) for time in UTC
Syntax:
Second(t: time) -> int
Examples:
Second(ParseTime("2001-03-19T13:52:06Z")) = 6
Seconds
converts duration in nanoseconds to seconds
Syntax:
Seconds(nanos: int) -> float
Examples:
Seconds(0.5 minutes) = 30
Seconds(7.5 seconds) = 7.5
Seconds(ParseTime("2020-02-24T12:00:05Z")-ParseTime("2020-02-24T12:00:00Z")) = 5
Time
converts argument to a time
Syntax:
Time(x: any) -> time?
Examples:
Time(1605892432653665000) = FromUnixNanos(1605892432653665000)
Time("2020-11-20T17:14:32Z") = ParseTime("2020-11-20T17:14:32Z")
Time(null) is null
Truncate
returns the result of rounding t down to a multiple of d (since the zero time)
Syntax:
Truncate(t: time, nanos: int) -> time
Examples:
Truncate(ParseTime("2020-01-01T17:32:49Z"), 4 hours) = ParseTime("2020-01-01T16:00:00Z")
UnixMillis
returns number of milliseconds since epoch for given time
Syntax:
UnixMillis(t: time) -> int
Examples:
UnixMillis(ParseTime("1980-01-01T00:00:00Z")) = 315532800000
UnixMillis(FromUnixMillis(25)) = 25
UnixNanos
returns number of nanoseconds since epoch for given time
Syntax:
UnixNanos(t: time) -> int
Examples:
UnixNanos(ParseTime("1980-01-01T00:00:00Z")) = 315532800000000000
UnixNanos(FromUnixNanos(25)) = 25
Weekday
returns day of week as number (Sunday=0 to Saturday=6) for time in UTC
Syntax:
Weekday(t: time) -> int
Examples:
Weekday(ParseTime("Monday, 19-Mar-01 13:52:06 UTC", "Monday, 02-Jan-06 15:04:05 MST")) = 1
Weeks
converts duration in nanoseconds to weeks
Syntax:
Weeks(nanos: int) -> float
Examples:
Weeks(10 weeks) = 10
Weeks(1 day) = 0.14285714285714285
Weeks(ParseTime("2020-02-24T12:00:00Z")-ParseTime("2020-02-10T12:00:00Z")) = 2
Year
returns year as number for time in UTC
Syntax:
Year(t: time) -> int
Examples:
Year(ParseTime("2001-03-19T13:52:06Z")) = 2001
YearDay
returns day of year as number for time in UTC
Syntax:
YearDay(t: time) -> int
Examples:
YearDay(ParseTime("2001-03-19T13:52:06Z")) = 78