Library time

This is exported from the core library, which means you don't need to import it.

Support for time and durations.
The Duration class represents relative times. That is, the time elapsed between two points in time.
The Time class represents the wallclock time as an Epoch time (read more: https://en.wikipedia.org/wiki/Unix_time).
The TimeInfo class is a human-friendly decomposition of a Time instance.
Examples

main:
  // In this example, we assume the time is 2021-04-21 15:30:35 UTC.
  now := Time.now
  // By default a time is stringified to UTC.
  print now         // >> 2021-04-21T15:30:35Z.
  print now.utc     // >> 2021-04-21T15:30:35Z.
  print now.local   // >> 2021-04-21T17:30:35.
  print now.local.h // >> 17.

  summing-duration := Duration.of:
    sum := 0
    1000.repeat: sum += it
    print sum  // >> 499500.
  print summing-duration // Prints the duration. For example: 1.118ms.

Classes

A Duration, capturing relative times.

A wall clock time.

A decomposed view of a Time object.

Functions

set-timezone rules/string -> any
Stores the given rules in the TZ environment variable and calls tzset, thus activating it.
Valid TZ values can be easily obtained by looking at the last line of the zoneinfo files on Linux machines:

tail -n1 /usr/share/zoneinfo/Europe/Copenhagen
Examples

set-timezone "CET-1CEST,M3.5.0,M10.5.0/3"  // Central European Timezone (as of 2024).
set-timezone "PST8PDT,M3.2.0,M11.1.0"  // Pacific Time (as of 2024).