On this page:
Time
Time.hour
Time.minute
Time.second
Time.nanosecond
Time.now
Time.from_  seconds
Time.to_  string

14.7.1 Time🔗ℹ

class

class date.Time(

  ~hour: hour :: Int.in(0 ..= 23) = 0,

  ~minute: minute :: Int.in(0 ..= 59) = 0,

  ~second: second :: Int.in(0 ..= 59) = 0,

  ~nanosecond: nanosecond :: Int.in(0, 999_999_999) = 0

)

Represents a time relative to an unspecified date and in an unspecified time zone.

The date.Time class privately implements Comparable, so date.Time instances can be compared with operators like < and >. A date.Time instance is serializable.

> def tm = date.Time(~hour: 5, ~minute: 45)

> tm

Time(~hour: 5, ~minute: 45, ~second: 0, ~nanosecond: 0)

> tm.to_string()

"05:45:00"

> tm < date.Time(~hour: 6, ~minute: 10)

#true

function

fun date.Time.now(~local: local :: Any = #true) :: date.Time

Uses the system clock via system.milliseconds to get the current time and using the operating system’s facilities to get a time of day relative to either the current time zone (when local is true) or UTC (when local is false).

function

fun date.Time.from_seconds(

  secs :: Real,

  ~local: local :: Any = #true

) :: date.Time

Uses operating system facilities to convert a number of seconds since the epoch to a time of day relative to either the current time zone (when local is true) or UTC (when local is false).

If the operating system reports a time within a leap second, then the reported time is the end of the preceding second.

> date.Time.from_seconds(0, ~local: #false)

Time(~hour: 0, ~minute: 0, ~second: 0, ~nanosecond: 0)

method

method (tm :: date.Time).to_string(

  ~time_format: time_format :: date.TimeFormat = #'seconds

) :: String

Converts tm to a string format depending on time_format. See date.TimeFormat for more information.

> def tm1 = date.Time(~hour: 5, ~minute: 45, ~second: 1, ~nanosecond: 70000)

> tm1.to_string()

"05:45:01"

> tm1.to_string(~time_format: #'nanoseconds)

"05:45:01.000070000"

> tm1.to_string(~time_format: #'auto_subseconds)

"05:45:01.000070"