timezone

tape
@profile(t1);
import io from "io";
import intl from "intl";
import timezone from "timezone";

fn main() -> i32 {
    let here: string = timezone.system_zone() or { "UTC" };
    io.println(here);                                   // Europe/Helsinki
    let fi: intl.Locale = intl.locale("fi") or { return 1; };
    let f: intl.DateTimeFormat = intl.date_time_format(fi, intl.Style.Medium, intl.Style.Short, here) or { return 1; };
    io.println(f.format(1782900000000000000));          // 1.7.2026 klo 13.00
    return 0;
}

timezone tells you which time zone the computer is set to, by the name the IANA time zone database gives it. A calendar or a booking form needs the name, not just today’s offset: time.local_offset is right for the instant you ask about, but the name lets intl work out the offset for any date, across daylight saving changes, past or future.

Functions

FunctionDoes
system_zone() -> ?stringThe computer’s zone: "Europe/Helsinki", "America/New_York", "UTC"; null when the system names none

The name is always one intl knows, in its current spelling (an old name such as Europe/Kiev comes back as Europe/Kyiv), so intl.zone and every intl date format accept it. When the system’s answer can’t be mapped to such a name, you get null rather than a name intl would refuse.

The system is asked on every call, so a zone the user changes while your program runs is seen.

Where the name comes from

  • Windows: the zone chosen in Settings (FLE Standard Time), mapped to the IANA name for your country or region (Windows uses one zone for Helsinki, Kyiv and Sofia; the country picks which name you get), by the table the Unicode CLDR project keeps. If “Adjust for daylight saving time automatically” is off, the clock keeps winter time all year and no named zone matches it: null.
  • Linux and macOS: the TZ environment variable when it’s set (Europe/Helsinki, :Europe/Helsinki, or a path into zoneinfo; a rule like EET-2EEST,M3.5.0/3,M10.5.0/4 names no zone, so null), else the zone /etc/localtime links to, else /etc/timezone.
  • Uusi: null; there are no time zones there yet.

Notes

  • timezone imports intl, so a program using it carries intl’s data (about 4 MB). That’s why this is a module of its own rather than part of time or os, which most programs import.
  • intl’s windows_zone and canonical_zone do the mapping and work on any name you give them, on any system.

Last modified: