Powered by AppSignal & Oban Pro

Time

elixir_livebooks/time.livemd

Time

A Time struct and functions.

The Time struct contains the fields hour, minute, second and microseconds. New times can be built with the new/4 function or using the ~T (see Kernel.sigil_T/2) sigil:

~T[23:00:07.001]

Both new/4 and sigil return a struct where the time fields can be accessed directly:

time = ~T[23:00:07.001]
time.hour
time.microsecond

The functions on this module work with the Time struct as well as any struct that contains the same fields as the Time struct, such as NaiveDateTime and DateTime. Such functions expect t:Calendar.time/0 in their typespecs (instead of t:t/0).

Developers should avoid creating the Time structs directly and instead rely on the functions provided by this module as well as the ones in third-party calendar libraries.

Comparing times

Comparisons in Elixir using ==/2, >/2, `= 0 ```