Skip to navigation

Time-related functions and constants.

Members

hour

time.hourtime.duration

A duration representing one hour.

microsecond

time.microsecondtime.duration

A duration representing one microsecond.

millisecond

time.millisecondtime.duration

A duration representing one millisecond.

minute

time.minutetime.duration

A duration representing one minute.

nanosecond

time.nanosecondtime.duration

A duration representing one nanosecond.

second

time.secondtime.duration

A duration representing one second.

from_timestamp

time.from_timestamp(sec, nsec?)

Converts the given Unix time corresponding to the number of seconds and (optionally) nanoseconds since January 1, 1970 UTC into a time object.

Parameters
secintSeconds since Unix epoch
nsec?optionalintNanoseconds component (optional)
Returns
resulttime.timeThe corresponding time value

is_valid_timezone

time.is_valid_timezone(loc)

Reports whether loc is a valid time zone name.

Parameters
locstringTime zone name to validate
Returns
resultboolTrue if the time zone name is valid

now

time.now()

Returns the current time. In workflow contexts, returns a deterministic time.

Returns
resulttime.timeThe current time

parse_duration

time.parse_duration(d)

Parses a duration string (e.g. “1h30m”, “300ms”).

Parameters
dstringDuration string to parse
Returns
resulttime.durationThe parsed duration

parse_time

time.parse_time(x, format?, location?)

Parses the given time string using a specific time format and location. Defaults to RFC3339 format and UTC location.

Parameters
xstringTime string to parse
format?optionalstringTime format string (default: RFC3339)
location?optionalstringTime zone name (default: UTC)
Returns
resulttime.timeThe parsed time value

time

time.time(year?, month?, day?, hour?, minute?, second?, nanosecond?, location?)

Returns the time corresponding to the given date and time components in the given location. All parameters are optional.

Parameters
year?optionalintYear
month?optionalintMonth (1-12)
day?optionalintDay of the month
hour?optionalintHour (0-23)
minute?optionalintMinute (0-59)
second?optionalintSecond (0-59)
nanosecond?optionalintNanosecond (0-999999999)
location?optionalstringTime zone name (default: UTC)
Returns
resulttime.timeThe constructed time value