Manuscript Documentation
v0.1.0

@std/time.ms#

Import each required symbol with import Name from "@std/time.ms".

Clock Interface#

A monotonic clock whose readings are suitable for measuring elapsed time.

Manuscript
interface Clock:
    fn now() -> Instant

Clock.now#

Returns the current reading of this monotonic clock. Readings are only comparable with others from the same clock and do not correspond to a calendar date.

Manuscript
fn now() -> Instant

Duration Native type#

A span of elapsed time.

Manuscript
type Duration:
    fn add(other: Duration) -> Duration:
    fn subtract(other: Duration) -> Duration:
    fn multiply(factor: Int) -> Duration:
    fn divide(divisor: Int) -> Duration:
    fn negate() -> Duration:
    fn abs() -> Duration:
    fn compare(other: Duration) -> Int:
    fn to_nanoseconds() -> Int:
    fn to_microseconds() -> Int:
    fn to_milliseconds() -> Int:
    fn to_seconds() -> Float:
    fn to_minutes() -> Float:
    fn to_hours() -> Float:

Duration.abs#

Returns the absolute value; the minimum Duration faults.

Manuscript
fn abs() -> Duration:

Duration.add#

Adds signed nanoseconds; a result outside Duration’s representable range faults.

Manuscript
fn add(other: Duration) -> Duration:

Duration.compare#

Returns -1, 0, or 1.

Manuscript
fn compare(other: Duration) -> Int:

Duration.divide#

Divides by a nonzero integer, truncating toward zero; zero faults.

Manuscript
fn divide(divisor: Int) -> Duration:

Duration.multiply#

Multiplies by an integer factor; overflow faults.

Manuscript
fn multiply(factor: Int) -> Duration:

Duration.negate#

Negates this duration; the minimum Duration faults.

Manuscript
fn negate() -> Duration:

Duration.subtract#

Subtracts signed nanoseconds; a result outside Duration’s representable range faults.

Manuscript
fn subtract(other: Duration) -> Duration:

Duration.to_hours#

Converts this duration to floating-point hours.

Manuscript
fn to_hours() -> Float:

Duration.to_microseconds#

Converts this duration to an integer number of microseconds.

Manuscript
fn to_microseconds() -> Int:

Duration.to_milliseconds#

Converts this duration to an integer number of milliseconds.

Manuscript
fn to_milliseconds() -> Int:

Duration.to_minutes#

Converts this duration to floating-point minutes.

Manuscript
fn to_minutes() -> Float:

Duration.to_nanoseconds#

Converts this duration to an integer number of nanoseconds.

Manuscript
fn to_nanoseconds() -> Int:

Duration.to_seconds#

Converts this duration to floating-point seconds.

Manuscript
fn to_seconds() -> Float:

Instant Native type#

An instant on a monotonic clock; it is not a calendar timestamp.

Manuscript
type Instant:
    fn shift(duration: Duration) -> Instant:
    fn difference(other: Instant) -> Duration:
    fn compare(other: Instant) -> Int:

Instant.compare#

Returns -1, 0, or 1; instants from different clock domains fault.

Manuscript
fn compare(other: Instant) -> Int:

Instant.difference#

Returns the elapsed duration from right to this instant.

Manuscript
fn difference(other: Instant) -> Duration:

Instant.shift#

Shifts this monotonic instant by a duration.

Manuscript
fn shift(duration: Duration) -> Instant:

TimeError Alternative#

Errors returned by timestamp parsing, arithmetic, or range conversion.

Manuscript
type TimeError:
    case InvalidInput
    case Closed
    case InvalidData
    case OutOfRange
Manuscript
impl Error for TimeError:
    fn message() -> String:

TimeError.Closed#

Reserved for time operations on a closed resource; the current native time operations do not return it.

Manuscript
case Closed

TimeError.InvalidData#

The text is not an RFC 3339 timestamp with a four-digit year, full date and time, and an explicit Z or +hh:mm offset.

Manuscript
case InvalidData

TimeError.InvalidInput#

Reserved for invalid time arguments; the current native time operations do not return it.

Manuscript
case InvalidInput

TimeError.OutOfRange#

A nanosecond component is outside 0 through 999999999, or the result falls outside years 1 through 9999 or cannot be represented as a Duration.

Manuscript
case OutOfRange

TimeError.Error.message#

Returns the fixed diagnostic time: <reason>, such as time: value out of range, without echoing the input text.

Manuscript
fn message() -> String:

Timestamp Native type#

A wall-clock time with Unix seconds and nanoseconds.

Manuscript
type Timestamp:
    fn to_string() -> String:
    fn unix_seconds() -> Int:
    fn nanoseconds() -> Int:
    fn shift(duration: Duration) -> Result[Timestamp, TimeError]:
    fn difference(other: Timestamp) -> Result[Duration, TimeError]:
    fn compare(other: Timestamp) -> Int:

Timestamp.compare#

Returns -1, 0, or 1 across the full calendar range.

Manuscript
fn compare(other: Timestamp) -> Int:

Timestamp.difference#

Returns self - right as a duration.

Manuscript
fn difference(other: Timestamp) -> Result[Duration, TimeError]:

Timestamp.nanoseconds#

Returns this timestamp’s nanosecond component.

Manuscript
fn nanoseconds() -> Int:

Timestamp.shift#

Adds a duration to this wall-clock timestamp.

Manuscript
fn shift(duration: Duration) -> Result[Timestamp, TimeError]:

Timestamp.to_string#

Formats this timestamp in RFC 3339 form.

Manuscript
fn to_string() -> String:

Timestamp.unix_seconds#

Returns the whole Unix seconds represented by this timestamp.

Manuscript
fn unix_seconds() -> Int:

WallClock Interface#

A clock that reports calendar time.

Manuscript
interface WallClock:
    fn now() -> Timestamp

WallClock.now#

Returns the current calendar time as a UTC Timestamp with nanosecond precision. It can jump when the system clock is adjusted, so use Clock for elapsed time.

Manuscript
fn now() -> Timestamp

clock Function#

Returns the monotonic clock used for elapsed-time measurements.

Manuscript
fn clock() -> Clock:

duration Function#

Constructs a duration from a number of nanoseconds.

Manuscript
fn duration(nanoseconds: Int) -> Duration:

parse_timestamp Function#

Parses an RFC 3339 timestamp with an explicit time zone.

Manuscript
fn parse_timestamp(text: String) -> Result[Timestamp, TimeError]:

sleep Function#

Suspends the current task for at least the requested duration.

Manuscript
fn sleep(duration: Duration) -> Unit:

timestamp Function#

Constructs a timestamp from Unix seconds and a nanosecond adjustment.

Manuscript
fn timestamp(seconds: Int, nanoseconds: Int) -> Result[Timestamp, TimeError]:

wall_clock Function#

Returns the wall clock used for calendar timestamps.

Manuscript
fn wall_clock() -> WallClock: