Skip to content

std/instant

Import with import std/instant.

Types

type Instant Int

opaque — construction surface is private to its defining module

Opaque absolute point in time. Backed by Unix epoch nanoseconds. Use Instant.to_seconds / Instant.from_seconds for the raw seconds-grained representation (sufficient for whole-second timestamps); Instant.add / Instant.between / Instant.before? for the opaque-typed arithmetic.

fn now(): Instant

type function on Instant

Read the current wall clock as an Instant. Single canonical “current time” function — there is no Int-returning variant. Use Instant.to_seconds(Instant.now()) if you need a seconds-grained representation.

fn from_seconds(n: Int): Instant

type function on Instant

Construct an Instant from whole seconds since the Unix epoch.

fn to_seconds(Instant(nanos)): Int

type function on Instant

Extract whole seconds since the Unix epoch from an Instant. Inverse of Instant.from_seconds; sub-second precision is truncated.

fn between(Instant(earlier), Instant(later)): Duration

type function on Instant

The Duration between two Instants (later minus earlier).

fn before?(Instant(a), Instant(b)): Bool

type function on Instant

Compare: is a strictly before b?

impl Add

fn add(Instant(nanos), rhs: Duration): Instant

impl Add.add

Add a Duration to an Instant, returning a new Instant.

impl Debug

fn inspect(value: Instant): String

impl Debug.inspect