Skip to main content

Time

Reference for mo:core/Time in the core library.

Time.now() is a trusted runtime read. Duration is a structured type whose conversion to nanoseconds is pure and contract-specified, which makes it the better choice for timer and deadline specifications.

Import

mo:core/Time

Status

  • Runtime module

Public API

Types

  • Time, Duration, TimerId

Functions

now() : Time

Reads the current system time from the runtime.

Use when: code or specifications need this operation with the documented contract.

toNanoseconds(duration : Duration) : Nat

Converts between the module type and the target representation.

Contract

ensures result == (switch duration {
case (#days n) n * 86_400_000_000_000;
case (#hours n) n * 3_600_000_000_000;
case (#minutes n) n * 60_000_000_000;
case (#seconds n) n * 1_000_000_000;
case (#milliseconds n) n * 1_000_000;
case (#nanoseconds n) n
});

Use when: crossing between this module's value and another representation.

Summary

  • Runtime module under mo:core/Time.
  • Exposes 2 public functions.