std.time
Duration struct
pub struct Duration :: [Equatable<Duration>, Ordered<Duration>, Hashable<Duration>, Display]
A distance between two instants, in whole milliseconds. May be negative: a.since(b) with
b later than a says so rather than hiding it.
millis: int
The distance in milliseconds; the sign is the direction.
pub static fn ofMillis(value: int): Duration
A duration of whole milliseconds.
pub static fn ofSeconds(value: int): Duration
A duration of whole seconds.
pub static fn ofMinutes(value: int): Duration
A duration of whole minutes.
pub fn totalMillis(): int
The whole distance in milliseconds.
pub fn totalSeconds(): int
The whole distance in seconds, truncated towards zero.
pub fn plus(other: Duration): Duration
The two added.
pub fn minus(other: Duration): Duration
The other subtracted from this one.
pub fn equals(other: Duration): bool
Whether the two span the same distance.
pub fn compare(other: Duration): int
The shorter distance first; a negative duration comes before a positive one.
Three comparisons rather than this.millis - other.millis: that subtraction overflows
for two durations far enough apart and hands back the opposite sign.
pub fn hash(): int
The millisecond count, which is what int hashes to.
pub fn show(): string
The distance with its unit: 1500ms, -500ms.
Milliseconds, not a scaled 1.5s: this type counts whole milliseconds, and a rendering
that divides them invents a precision the value does not carry. Scaled forms are
std.fmt work.
stdlib/std/time.lyr:26
TimeError class
pub class TimeError :: [Throwable]
A failed reading of a time text: what was handed in, and what broke.
text: string
What went wrong, naming the field that broke.
pub fn message(): string
stdlib/std/time.lyr:100
Instant struct
pub struct Instant :: [Equatable<Instant>, Ordered<Instant>, Hashable<Instant>, Display]
A point on the wall clock: milliseconds since 1970-01-01 UTC.
millis: int
Milliseconds since the epoch; negative is before 1970.
pub static fn now(): Instant
The wall clock, now.
pub static fn ofEpochMillis(value: int): Instant
The instant at these epoch milliseconds — for stored timestamps and for tests, which want a clock that stands still.
pub fn epochMillis(): int
Milliseconds since the epoch — the raw number back, for storing.
pub fn since(earlier: Instant): Duration
The distance from earlier to this instant. Negative when earlier is actually later.
pub fn plus(d: Duration): Instant
This instant moved by a duration; a negative one moves backwards.
pub fn iso(): string
ISO 8601 in UTC, millisecond precision: 1970-01-01T00:00:00.000Z.
divFloor/modFloor rather than / and %, so an instant BEFORE the epoch lands in
the right day — truncation would round the day towards 1970 and hand the rest a negative
time.
pub static fn fromIso(text: string): ?Instant
Reads what iso() writes — the round-trip half that was missing since iso exists:
fromIso(x.iso()) is x, pre-epoch instants included. null when the text is not
that shape or names a day that does not exist; fromIsoOrThrow says which field broke.
Strict on purpose: exactly YYYY-MM-DDTHH:MM:SS.mmmZ, UTC only. A parser that accepts
offsets or shortened forms would be promising calendar arithmetic this module does not
have; the day 31 of February is refused rather than silently carried into March.
pub static fn fromIsoOrThrow(text: string): Instant throws TimeError
fromIso, with the reason when the text does not read.
pub fn equals(other: Instant): bool
Whether the two name the same point on the clock.
pub fn compare(other: Instant): int
The earlier instant first.
Three comparisons rather than this.millis - other.millis: an instant near the epoch
against one near the type's maximum overflows that subtraction, and the sign it hands
back is the wrong one.
pub fn hash(): int
The epoch milliseconds, which is what int hashes to.
pub fn show(): string
The ISO 8601 form — the same text iso() writes, because it is the one textual shape
this type has.
stdlib/std/time.lyr:110