is_eq : _
Are two Times equal? Two values are equal only when all of their parts match.
Time :: # (opaque)
The Time module provides the Time type as well as functions for working with time values.
These functions include functions for creating Time objects from various numeric values, converting Times to and from ISO 8601 strings, and performing arithmetic operations on Times.
is_eq : _
Are two Times equal? Two values are equal only when all of their parts match.
to_hash : _
Hash a Time, so it can be used as a Dict key or Set element. Agrees with is_eq.
to_inspect : Time -> Str
Show the Time as an ISO 8601 string, such as 09:30:00 or 09:30:00,5.
This is what Str.inspect, dbg, and failing expect reports use.
The hour of the Time, from 0 to 23.
The minute of the Time, from 0 to 59.
The second of the Time, from 0 to 59.
nanosecond : Time -> U32
The nanosecond of the Time, from 0 to 999,999,999.
add : Time, Duration -> Time
Same as add_duration and plus.
plus : Time, Duration -> Time
Add a Duration to a Time. Backs the + operator. Same as add_duration.
minus : Time, Duration -> Time
Subtract a Duration from a Time, wrapping around midnight. Backs the - operator.
To get the Duration between two Times, use sub instead.
add_duration : Time, Duration -> Time
Add a Duration to a Time, wrapping around midnight: 23:00:00 plus two hours is 01:00:00.
Same as plus, which backs the + operator.
Use add_duration_with_day_offset to also learn how many days were crossed.
add_duration_with_day_offset : Time, Duration -> { time : Time, day_offset : I64 }
Add a Duration to a Time, wrapping around midnight, and also return the number of whole days crossed.
Time.from_hms(23, 0, 0)?.add_duration_with_day_offset(Duration.from_hours(2)) == { time: Time.from_hms(1, 0, 0)?, day_offset: 1 }
Time.from_hms(1, 0, 0)?.add_duration_with_day_offset(Duration.from_hours(-2)) == { time: Time.from_hms(23, 0, 0)?, day_offset: -1 }
Add hours to a Time, wrapping around midnight.
add_minutes : Time, I64 -> Time
Add minutes to a Time, wrapping around midnight.
add_nanoseconds : Time, I64 -> Time
Add nanoseconds to a Time, wrapping around midnight.
add_seconds : Time, I64 -> Time
Add seconds to a Time, wrapping around midnight.
Determine if the first Time occurs after the second Time.
Determine if the first Time occurs before the second Time.
Whether the first Time is before the second. This is what the < operator uses.
Whether the first Time is after the second. This is what the > operator uses.
Whether the first Time is before or the same as the second. This is what the <= operator uses.
Whether the first Time is after or the same as the second. This is what the >= operator uses.
min : Time, Time -> Time
The earlier of two Times. Returns the first when they are equal. Lets List.min work on a List(Time).
max : Time, Time -> Time
The later of two Times. Returns the first when they are equal. Lets List.max work on a List(Time).
order_relative_to : Time, Time -> [Before, Same, After]
Compare two Time objects.
If the first occurs before the second, it returns Before.
If the first and the second are equal, it returns Same.
If the first occurs after the second, it returns After.
This is what List.sort and List.sort_by use.
Format a Time object according to the given format string.
The following placeholders are supported:
{hh}: 2-digit hour (00-23){h}: hour (0-23){mm}: 2-digit minute (00-59){m}: minute (0-59){ss}: 2-digit second (00-59){s}: second (0-59){f} or {f:}: fractional part of the second{f:x}: fractional part of the second with x digits{n}: nanosecond (0-999,999,999)Create a Time from the hour, minute, and second. The hour must be 0 to 23, and the minute and second 0 to 59.
ISO 8601's end-of-day notation 24:00:00 names the next day's midnight, so it is accepted by
from_iso_str but not here.
from_hmsn : U8, U8, U8, U32 -> Try(Time, [InvalidHour, InvalidMinute, InvalidSecond, InvalidNanosecond])
Create a Time from the hour, minute, second, and nanosecond. The hour must be 0 to 23, the minute and second 0 to 59,
and the nanosecond 0 to 999,999,999. See from_hms.
from_iso_str : Str -> Try(Time, [InvalidTimeFormat])
Convert an ISO 8601 string to a Time object.
The result is always a time of day from 00:00:00 up to but not including 24:00:00.
The end-of-day notation 24:00:00 gives midnight, and a UTC offset that carries the time across midnight wraps around,
so "23:00:00-05:00" gives 04:00:00.
Use from_iso_str_with_day_offset to find out how many days were carried.
from_iso_u8 : List(U8) -> Try(Time, [InvalidTimeFormat])
Convert an ISO 8601 list of UTF-8 bytes to a Time object. See from_iso_str.
from_iso_str_with_day_offset : Str -> Try({ time : Time, day_offset : I64 }, [InvalidTimeFormat])
Convert an ISO 8601 string to a Time object, along with the number of days the time was carried across midnight.
Time.from_iso_str_with_day_offset("23:00:00-05:00") == Ok({ time: Time.from_hms(4, 0, 0)?, day_offset: 1 })
Time.from_iso_str_with_day_offset("01:00:00+03:00") == Ok({ time: Time.from_hms(22, 0, 0)?, day_offset: -1 })
Time.from_iso_str_with_day_offset("24:00:00") == Ok({ time: Time.midnight, day_offset: 1 })
from_iso_u8_with_day_offset : List(U8) -> Try({ time : Time, day_offset : I64 }, [InvalidTimeFormat])
Convert an ISO 8601 list of UTF-8 bytes to a Time object, along with the number of days the time was carried across midnight.
See from_iso_str_with_day_offset.
from_nanos_since_midnight : I64 -> Try(Time, [NanosecondsOutOfRange])
Convert nanoseconds since midnight to a Time. The value must be at least 0 and less than the number of nanoseconds in a day.
To wrap a value around midnight instead, add it to midnight with add_nanoseconds.
midnight : Time
Time object representing 00:00:00.
highest : Time
The latest Time that can be represented: 23:59:59.999999999, the last nanosecond of the day.
lowest : Time
The earliest Time that can be represented: 00:00:00. Same as midnight.
normalize : Time -> Time
Every Time is already a valid time of day, so this returns its input unchanged.
It is kept for code written when a Time could hold an hour outside 0 to 23.
sub : Time, Time -> Duration
Subtract two Time objects to get the Duration between them. The result is negative when the first is earlier.
This is not the - operator: time - duration calls minus and gives a Time.
from_quote : Str -> Try(Time, [BadQuotedBytes(Str)])
Let a string literal be used where a Time is expected, so the ISO 8601 time is checked at compile time.
standup : Time
standup = "09:30:00"
An invalid literal is a compile-time error.
to_iso_str : Time -> Str
Convert a Time object to an ISO 8601 string.
Convert a Time object to an ISO 8601 list of UTF-8 bytes.
to_nanos_since_midnight : Time -> I64
Convert a Time object to the number of nanoseconds since midnight.