Lyric v4.0.0

std.time

Duration struct

pub struct Duration

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.

stdlib/std/time.lyr:25

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:66

Instant struct

pub struct Instant

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.

stdlib/std/time.lyr:76