Manuscript Documentation
v2026.12.0

@std/time.ms#

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

CalendarDate Type#

A proleptic Gregorian calendar date without time of day or time zone, from 0001-01-01 through 9999-12-31. Build a validated date with calendar_date(year, month, day), parse_date("2026-11-30"), or Date.calendar_date().

Manuscript
type CalendarDate {
    year Int
    month Int
    day Int
}

CalendarDate.day#

The day of the month, 1 through 31.

Manuscript
day Int

CalendarDate.month#

The month, 1 (January) through 12.

Manuscript
month Int

CalendarDate.year#

The year, 1 through 9999.

Manuscript
year Int

CalendarDate.add_days#

Returns the date days days after this one (days may be negative). Returns ERANGE if the result falls outside 0001-01-01 through 9999-12-31.

Manuscript
fn add_days(days Int) Result[CalendarDate, Error]

CalendarDate.add_months#

Returns the date months months after this one (months may be negative), clamping the day to the last day of the target month (e.g. Jan 31 + 1 month is Feb 28/29). Returns ERANGE if the result falls outside years 1 through 9999.

Manuscript
fn add_months(months Int) Result[CalendarDate, Error]

CalendarDate.add_years#

Returns the date years years after this one (years may be negative), clamping Feb 29 to Feb 28 in non-leap years. Returns ERANGE if the result falls outside years 1 through 9999.

Manuscript
fn add_years(years Int) Result[CalendarDate, Error]

CalendarDate.compare#

Returns -1 when this date is earlier than other, 0 when equal, and 1 when later.

Manuscript
fn compare(other CalendarDate) Int

CalendarDate.day_of_year#

Returns the 1-based day of the year (1 through 366).

Manuscript
fn day_of_year() Int

CalendarDate.days_between#

Returns the signed number of calendar days from other to this date (self - other).

Manuscript
fn days_between(other CalendarDate) Int

CalendarDate.is_leap_year#

Reports whether this date’s year is a Gregorian leap year.

Manuscript
fn is_leap_year() Bool

CalendarDate.to_json#

Writes the date as an ISO 8601 YYYY-MM-DD JSON string.

Manuscript
fn to_json() JsonValue

CalendarDate.to_string#

Formats as ISO 8601 YYYY-MM-DD, such as 2026-11-30.

Manuscript
fn to_string() String

CalendarDate.to_timestamp#

Converts this date to midnight (00:00:00) in zone (default "UTC"), using the same zone rules as from_calendar.

Manuscript
fn to_timestamp(zone String = "UTC") Result[Timestamp, Error]

CalendarDate.weekday#

Returns the day of the week, 0 (Sunday) through 6 (Saturday).

Manuscript
fn weekday() Int

Date Type#

Date and time fields of a timestamp in one time zone.

Manuscript
type Date {
    year Int
    month Int
    day Int
    hour Int
    minute Int
    second Int
    nanosecond Int
    weekday Int
    day_of_year Int
    offset_seconds Int
    zone String
}

Date.day#

The day of the month, starting at 1.

Manuscript
day Int

Date.day_of_year#

The day of the year, starting at 1.

Manuscript
day_of_year Int

Date.hour#

The hour, 0 through 23.

Manuscript
hour Int

Date.minute#

The minute, 0 through 59.

Manuscript
minute Int

Date.month#

The month, 1 (January) through 12.

Manuscript
month Int

Date.nanosecond#

The nanosecond within the second, 0 through 999999999.

Manuscript
nanosecond Int

Date.offset_seconds#

The zone’s offset from UTC in seconds at this moment; positive is east.

Manuscript
offset_seconds Int

Date.second#

The second, 0 through 59.

Manuscript
second Int

Date.weekday#

The day of the week, 0 (Sunday) through 6 (Saturday).

Manuscript
weekday Int

Date.year#

The year, 1 through 9999 in UTC and nearby values in other zones.

Manuscript
year Int

Date.zone#

The zone abbreviation at this moment, such as UTC or EST.

Manuscript
zone String

Date.calendar_date#

Extracts the calendar date (year, month, day) without time of day or zone.

Manuscript
fn calendar_date() CalendarDate

Deadline Type#

A point on the monotonic clock to wait for or check against, such as the end of a request’s time budget.

Manuscript
type Deadline {
    at Instant
}

Deadline.at#

The instant the deadline expires.

Manuscript
at Instant

Deadline.is_expired#

Reports whether the deadline has passed.

Manuscript
fn is_expired() Bool

Deadline.remaining#

Returns the time left, or zero once the deadline has passed.

Manuscript
fn remaining() Duration

Deadline.wait#

Suspends the current task until the deadline passes. Returns at once if it already has.

Manuscript
fn wait() Void

Duration Type#

A span of elapsed time, counted in signed nanoseconds.

Manuscript
type Duration {
    nanos Int
}

Duration.nanos#

The signed count of nanoseconds; nanoseconds(n) and the unit constructors build one.

Manuscript
nanos Int

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.clamp#

Returns this value limited to low through high; low greater than high is a programming fault.

Manuscript
fn clamp(low Duration, high Duration) Duration

Duration.compare#

Returns -1 when this duration is shorter than other, 0 when equal and 1 when longer.

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.max#

Returns the greater of this value and other, or this value when they compare equal.

Manuscript
fn max(other Duration) Duration

Duration.min#

Returns the lesser of this value and other, or this value when they compare equal.

Manuscript
fn min(other Duration) 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_json#

Writes the signed nanoseconds as a JSON integer.

Manuscript
fn to_json() JsonValue

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

Duration.to_string#

Returns human text such as 1m30.5s, 250ms, 1.5µs, -2h0m0s, or 0s; string interpolation uses it too. A larger unit is followed by every smaller whole unit down to seconds, so two minutes is 2m0s and an exact hour is 1h0m0s.

Manuscript
fn to_string() String

Instant Type#

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

Manuscript
type Instant {
    domain Int
    tick Int
}

Instant.domain#

The clock the reading belongs to; instants from different domains do not compare.

Manuscript
domain Int

Instant.tick#

Nanoseconds on that clock.

Manuscript
tick Int

Instant.clamp#

Returns this value limited to low through high; low greater than high is a programming fault.

Manuscript
fn clamp(low Instant, high Instant) Instant

Instant.compare#

Returns -1 when this instant is earlier than other, 0 when equal and 1 when later. Instants from different clock domains fault.

Manuscript
fn compare(other Instant) Int

Instant.difference#

Returns this instant minus other: the time elapsed since other, negative when other is later.

Manuscript
fn difference(other Instant) Duration

Instant.max#

Returns the greater of this value and other, or this value when they compare equal.

Manuscript
fn max(other Instant) Instant

Instant.min#

Returns the lesser of this value and other, or this value when they compare equal.

Manuscript
fn min(other Instant) Instant

Instant.shift#

Shifts this monotonic instant by a duration.

Manuscript
fn shift(duration Duration) Instant

Timestamp Type#

A wall-clock time with Unix seconds and nanoseconds.

Manuscript
type Timestamp {
    seconds Int
    nanos Int
}

Timestamp.nanos#

The nanosecond within the second, 0 through 999999999.

Manuscript
nanos Int

Timestamp.seconds#

Whole seconds since the Unix epoch.

Manuscript
seconds Int

Timestamp.calendar#

Breaks this timestamp into calendar fields in a time zone: "UTC", "Local", an IANA name such as "America/New_York", or a fixed offset such as "+05:30". An unknown zone returns EINVAL.

Manuscript
fn calendar(zone String) Result[Date, Error]

Timestamp.clamp#

Returns this value limited to low through high; low greater than high is a programming fault.

Manuscript
fn clamp(low Timestamp, high Timestamp) Timestamp

Timestamp.compare#

Returns -1 when this timestamp is earlier than other, 0 when equal and 1 when later, across the full calendar range.

Manuscript
fn compare(other Timestamp) Int

Timestamp.difference#

Returns this timestamp minus other as a duration. A result that does not fit a Duration returns ERANGE.

Manuscript
fn difference(other Timestamp) Result[Duration, Error]

Timestamp.format#

Formats this timestamp in a zone with a token pattern. The tokens are YYYY, MM, DD, HH, mm, ss, SSS (milliseconds), ZZ (offset such as +05:30) and zone (abbreviation). Other text is copied. Tokens are replaced wherever they appear, even inside words ("Dummy" becomes "Du13y"), and there is no escape. To include literal letters that spell a token, format the fields separately and join the pieces yourself. An unknown zone returns EINVAL.

Manuscript
fn format(pattern String, zone String) Result[String, Error]

Timestamp.max#

Returns the greater of this value and other, or this value when they compare equal.

Manuscript
fn max(other Timestamp) Timestamp

Timestamp.min#

Returns the lesser of this value and other, or this value when they compare equal.

Manuscript
fn min(other Timestamp) Timestamp

Timestamp.nanoseconds#

Returns this timestamp’s nanosecond component.

Manuscript
fn nanoseconds() Int

Timestamp.shift#

Adds a duration to this wall-clock timestamp. A result outside years 1 through 9999 returns ERANGE.

Manuscript
fn shift(duration Duration) Result[Timestamp, Error]

Timestamp.to_json#

Writes the RFC 3339 text as a JSON string.

Manuscript
fn to_json() JsonValue

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

calendar_date Function#

Validates and constructs a Gregorian CalendarDate for years 1 through 9999. Invalid dates (such as February 29 in a non-leap year) return EINVAL.

Manuscript
fn calendar_date(year Int, month Int, day Int) Result[CalendarDate, Error] { ... }

deadline_after Function#

Returns a deadline duration from now.

Manuscript
fn deadline_after(duration Duration) Deadline { ... }

from_calendar Function#

Builds a timestamp from calendar fields interpreted in a time zone (see Timestamp.calendar for zone names). Fields outside their calendar range, such as month 13 or February 30, return ERANGE; an unknown zone returns EINVAL. A local time skipped or repeated by a daylight-saving change resolves to the earlier valid offset.

Manuscript
fn from_calendar(year Int, month Int, day Int, hour Int, minute Int, second Int, nanosecond Int, zone String) Result[Timestamp, Error] { ... }

hours Function#

Constructs a duration of n hours; n may be negative, and a nanosecond count outside Int faults like any Int multiplication.

Manuscript
fn hours(n Int) Duration { ... }

local_zone Function#

Returns the host’s local time zone name, or UTC when it cannot be determined.

Manuscript
fn local_zone() String { ... }

microseconds Function#

Constructs a duration of n microseconds; n may be negative, and a nanosecond count outside Int faults like any Int multiplication.

Manuscript
fn microseconds(n Int) Duration { ... }

milliseconds Function#

Constructs a duration of n milliseconds; n may be negative, and a nanosecond count outside Int faults like any Int multiplication.

Manuscript
fn milliseconds(n Int) Duration { ... }

minutes Function#

Constructs a duration of n minutes; n may be negative, and a nanosecond count outside Int faults like any Int multiplication. For example, monotonic().difference(start).compare(minutes(5)) > 0 tests whether more than five minutes have elapsed.

Manuscript
fn minutes(n Int) Duration { ... }

monotonic Function#

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

Manuscript
fn monotonic() Instant { ... }

nanoseconds Function#

Constructs a duration of n nanoseconds, the unit Duration counts in; n may be negative.

Manuscript
fn nanoseconds(n Int) Duration { ... }

now Function#

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

Manuscript
fn now() Timestamp { ... }

parse_date Function#

Parses a strict ISO 8601 YYYY-MM-DD date string. Malformed text or an invalid calendar date returns EBADMSG.

Manuscript
fn parse_date(text String) Result[CalendarDate, Error] { ... }

parse_duration Function#

Parses a span such as 1h30m, -250ms or 1.5µs, including every Duration.to_string() result. Accepts one optional leading + or -, then decimal components with the units ns, us, µs, μs, ms, s, m or h. Components may repeat or appear in any order; .5s and 1.s are valid. A bare 0 is also valid, including +0 and -0. Fractions may have any number of ASCII digits. Each component truncates toward zero to whole nanoseconds, without floating-point rounding, and negative zero becomes zero. Whitespace, exponents, missing units and other syntax return EBADMSG, even after an overflowing prefix. A well-formed span outside -9223372036854775808 through 9223372036854775807 nanoseconds returns ERANGE.

Manuscript
fn parse_duration(text String) Result[Duration, Error] { ... }

parse_timestamp Function#

Parses an RFC 3339 timestamp with an explicit time zone.

Manuscript
fn parse_timestamp(text String) Result[Timestamp, Error] { ... }

seconds Function#

Constructs a duration of n seconds, as in sleep(seconds(2)); n may be negative, and a nanosecond count outside Int faults like any Int multiplication.

Manuscript
fn seconds(n Int) Duration { ... }

sleep Function#

Starts a timer for the requested duration and returns its promise; wait() it to pause the current task for at least that long. The timer has no task of its own, and dropping the promise cancels it.

Manuscript
fn sleep(duration Duration) Promise[Void] { ... }

ticker Function#

Returns a ticker whose first tick comes one period from now. A period of zero or less is a programming fault.

Manuscript
fn ticker(period Duration) ReadStream[Instant] { ... }

timestamp Function#

Constructs a timestamp from Unix seconds and the nanosecond within that second. nanoseconds must be 0 through 999999999, and seconds from -62135596800 (year 1) through 253402300799 (year 9999); anything else returns ERANGE. It does not carry extra nanoseconds into the seconds.

Manuscript
fn timestamp(seconds Int, nanoseconds Int) Result[Timestamp, Error] { ... }