#tz package

    Time zone support layered on top of core's NaiveDateTime. Import connect0459/almanac/tz for the TimeZone trait, Utc, FixedOffset, DateTime[Tz], and Location (IANA tzdata lookup by zone name, e.g. "America/New_York").

    #Key types

    TypeDescription
    TimeZone (trait)Resolves a NaiveDateTime to a UTC offset; implemented by Utc, FixedOffset, FixedZone, and Location
    MappedLocalTime[T]The result of resolving a local (wall-clock) reading: Single, Ambiguous (DST fold), or Absent (DST gap); T is a FixedOffset or a DateTime[Tz]
    UtcThe UTC zone: always offset zero
    FixedOffsetA constant UTC offset, ±23:59:59
    FixedZoneA named zone with one constant offset; zone_name/%Z report the name
    DateTime[Tz]A NaiveDateTime paired with a time zone Tz
    LocationA time zone backed by parsed IANA tzdata, resolving historical transitions and DST
    TransitionBoundsThe validity window (start/end) of a Location's segment covering a given instant

    #Quick start

    Attaching a time zone to a UTC instant and reading it back in local time:

    ///|
    test {
    let naive = @core.NaiveDateTime::new(
    @core.NaiveDate::from_ymd(2024, 6, 15).unwrap(),
    @core.NaiveTime::from_hms(12, 0, 0).unwrap(),
    )
    let dt = @tz.DateTime::from_utc(
    naive,
    @tz.FixedOffset::east(9 * 3600).unwrap(),
    )
    assert_eq(dt.offset(), @tz.FixedOffset::east(9 * 3600).unwrap())
    assert_eq(
    dt.naive_local(),
    @core.NaiveDateTime::new(
    @core.NaiveDate::from_ymd(2024, 6, 15).unwrap(),
    @core.NaiveTime::from_hms(21, 0, 0).unwrap(),
    ),
    )
    }

    DateTime::round/truncate operate on the underlying UTC instant, not the offset-shifted local presentation — truncating to an hour boundary in UTC can still leave a non-zero local minute under a non-whole-hour FixedOffset:

    ///|
    test {
    let naive = @core.NaiveDateTime::new(
    @core.NaiveDate::from_ymd(2024, 6, 15).unwrap(),
    @core.NaiveTime::from_hms(12, 15, 0).unwrap(),
    )
    let dt = @tz.DateTime::from_utc(
    naive,
    @tz.FixedOffset::east(9 * 3600 + 1800).unwrap(),
    )
    let truncated = dt.truncate(@core.TimeDelta::hours(1L).unwrap()).unwrap()
    assert_eq(
    truncated.naive_utc(),
    @core.NaiveDateTime::new(
    @core.NaiveDate::from_ymd(2024, 6, 15).unwrap(),
    @core.NaiveTime::from_hms(12, 0, 0).unwrap(),
    ),
    )
    assert_eq(
    truncated.naive_local(),
    @core.NaiveDateTime::new(
    @core.NaiveDate::from_ymd(2024, 6, 15).unwrap(),
    @core.NaiveTime::from_hms(21, 30, 0).unwrap(),
    ),
    )
    }

    Looking up a real IANA zone by name and resolving its offset at a known DST transition:

    ///|
    test {
    let ny = @tz.Location::load("America/New_York").unwrap()
    let dst_start_2024 = @core.NaiveDateTime::from_timestamp(1_710_054_000L, 0).unwrap()
    assert_eq(
    ny.offset_from_utc(dst_start_2024),
    @tz.FixedOffset::east(-14400).unwrap(),
    )
    assert_eq(ny.zone_name(dst_start_2024), "EDT")
    }

    #Embedded tz database

    Location::load reads a snapshot of the IANA tz database compiled into the package: release 2026c, 598 zones, taken from the compiled rearguard data of a macOS system (/var/db/timezone/zoneinfo). Zone rules change after a release, so a zone that changed later (a government altering its DST rule) keeps its old rules until the snapshot is regenerated. The release is also named in the header of tzdata_generated.mbt.

    To regenerate from another compiled zoneinfo tree, such as one built with zic from a specific release, run just gen-tzdata <zoneinfo dir>; the release is read from the tree's +VERSION file.

    #API reference

    #TimeZone trait

    Implemented by Utc, FixedOffset, FixedZone, Location, and PosixTz. The trait is readonly: other packages can use Tz : TimeZone as a bound but cannot implement it, so these are the only zones. DateTime[Tz]::offset/naive_local require Tz : TimeZone.

    Zone names have two roles with two spellings: name() (on Location and FixedZone) is the identifier that distinguishes the zone, such as the IANA id "Asia/Tokyo", while zone_name (on every TimeZone, and on DateTime) is the name in effect at an instant, such as the abbreviation "JST" or "EDT", "UTC", or a bare FixedOffset's offset text. DateTime::timezone() returns the zone value itself, as with_timezone takes one.

    Every NaiveDateTime argument is a UTC reading except the one taken by offset_from_local, which is a local (wall-clock) reading. The type does not tell them apart, so pass DateTime::naive_utc() for the former and DateTime::naive_local() for the latter. To build a DateTime from either reading, use DateTime::from_utc/DateTime::from_local.

    MethodSignatureDescription
    offset_from_utc(NaiveDateTime)-> FixedOffsetThe offset in effect at a given UTC instant; never ambiguous
    offset_from_local(NaiveDateTime)-> MappedLocalTime[FixedOffset]The offset(s) for a given local (wall-clock) instant, handling DST ambiguity/gaps
    zone_name(NaiveDateTime)-> StringThe zone abbreviation/name in effect at a given UTC instant
    is_dst(NaiveDateTime)-> BoolWhether daylight saving time is in effect at a given UTC instant; false by default, overridden by Location, PosixTz and Local
    transition_bounds(NaiveDateTime)-> TransitionBoundsThe validity window of the offset in effect at a given UTC instant; unbounded on both sides by default, overridden by Location (its own transition_bounds), PosixTz and Local
    offset_from_abbreviation(String, NaiveDateTime)-> FixedOffset?The offset a zone abbreviation (e.g. "EST") denotes in this zone, resolved at a given UTC instant; None by default (Utc, FixedOffset), overridden by Location (see its own method), PosixTz (its standard and DST names) and Local


    #MappedLocalTime[T]

    ///|
    pub enum MappedLocalTime[T] {
    Single(T)
    Ambiguous(T, T) // a DST fold: two valid results, (earliest, latest)
    Absent // a DST gap: no valid result
    }

    Absent also covers components that do not form a valid reading (for example month 13) when the result is built from components (DateTime::from_ymd_hms, DateTime::with_*); to tell an invalid component from a gap, validate first with NaiveDate::from_ymd/NaiveTime::from_hms.

    Utc and FixedOffset only ever produce Single (neither has daylight saving). A Location can produce all three around a real DST transition: Ambiguous when a local clock reading occurs twice (the fold at the end of DST), and Absent when a local clock reading never occurs (the gap at the start of DST). T is usually a FixedOffset (TimeZone::offset_from_local) or a DateTime[Tz] (DateTime::from_local/from_ymd_hms).

    MethodSignatureDescription
    single()-> T?The value, only when unambiguous; None for Ambiguous/Absent
    unwrap()-> TThe value when unambiguous; aborts, naming the reason, on Ambiguous or Absent
    earliest()-> T?The earliest possible value (the sole value, or the first of an Ambiguous fold); None for Absent
    latest()-> T?The latest possible value (the sole value, or the second of an Ambiguous fold); None for Absent
    map((T) -> U)-> MappedLocalTime[U]Transform every value carried by self, preserving its shape

    MappedLocalTime[T] also implements Eq (when T : Eq).

    There is deliberately no and_then. A step that itself returns a MappedLocalTime, applied to both sides of an Ambiguous, could yield up to four values with no obvious one to keep. Reduce to one value first with single(), earliest() or latest(), then continue; that choice stays with the caller:

    ///|
    test {
    let dt = @tz.DateTime::from_ymd_hms(2024, 3, 5, 9, 0, 0, @tz.Utc::new()).unwrap()
    let moved = dt.with_hour(10).single().bind(d => d.with_minute(30).single())
    assert_eq(moved.map(d => d.hour() * 100 + d.minute()), Some(1030))
    }


    #Utc

    The UTC zone, always offset zero.

    MethodSignatureDescription
    Utc::new()-> SelfConstruct the (zero-sized) UTC zone value
    Utc::now()-> DateTime[Utc]The current UTC instant, read from the host's wall clock. Unlike every other function in this package, not a pure function of its arguments. Total: a host clock outside NaiveDate's range (about 5.8 million years either side of 1970) is a broken environment, and aborts.
    offset_from_utc(NaiveDateTime)-> FixedOffsetAlways FixedOffset::east(0)
    offset_from_local(NaiveDateTime)-> MappedLocalTime[FixedOffset]Always Single(FixedOffset::east(0))
    zone_name(NaiveDateTime)-> StringAlways "UTC"
    to_string() (Show)-> String"UTC", the same text as zone_name

    Utc also implements Eq and TimeZone.


    #FixedOffset

    A constant UTC offset, in seconds, within ±23:59:59.

    Naming rule: a name with offset (DateTime::offset, offset_from_utc, offset_from_local) yields a FixedOffset value, while utc_offset and local_minus_utc yield the same quantity as a plain Int number of seconds.

    MethodSignatureDescription
    FixedOffset::east(Int)-> Self?An offset east of UTC by the given seconds; None outside ±23:59:59
    FixedOffset::west(Int)-> Self?An offset west of UTC by the given seconds (negated internally); same range
    local_minus_utc()-> IntThe offset in seconds (negative for a western offset)
    utc_minus_local()-> IntThe sign-reversed offset in seconds (positive for a western offset)
    offset_from_utc(NaiveDateTime)-> FixedOffsetReturns self, unchanged, regardless of the given instant
    offset_from_local(NaiveDateTime)-> MappedLocalTime[FixedOffset]Always Single(self)
    zone_name(NaiveDateTime)-> StringColon-separated sign, hour, and minute, e.g. "+09:00"; extended with a seconds component for a non-whole-minute offset, e.g. "-04:56:02"
    to_string() (Show)-> StringThe same colon-separated text as zone_name, e.g. "+09:00"

    FixedOffset also implements Eq and TimeZone.


    #FixedZone

    A named zone with a constant offset and no daylight saving. Unlike a bare FixedOffset, whose zone_name is its own offset text ("+09:00"), a FixedZone's zone_name (and so %Z) is the name it was given. Two zones are equal only when both the name and the offset match, so FixedOffset's own equality and rendering are unaffected.

    MethodSignatureDescription
    FixedZone::new(String, FixedOffset)-> SelfA zone with the given name and constant offset
    name()-> StringThe zone's name
    offset()-> FixedOffsetThe zone's constant offset
    offset_from_utc(NaiveDateTime) / offset_from_local(NaiveDateTime)-> FixedOffset / -> MappedLocalTime[FixedOffset]The constant offset; the local form is always Single
    zone_name(NaiveDateTime)-> StringThe zone's name
    offset_from_abbreviation(String, NaiveDateTime)-> FixedOffset?The offset when the abbreviation equals the zone's own name, else None, so parse_date_time_in can read a %Z name back

    #DateTime[Tz]

    A NaiveDateTime paired with a time zone Tz. The UTC instant is stored directly; the local (wall-clock) representation is derived on demand.

    Eq, Hash and Compare all identify the UTC instant and ignore the zone value, so the same instant in different zones is equal, hashes alike and compares as 0; compare the zones themselves (or naive_local()) when the wall-clock reading matters. Utc, FixedOffset, Location and TransitionBounds implement Hash too, so all of them can key a Map.

    MethodSignatureDescription
    DateTime::from_utc(NaiveDateTime, Tz)-> Self[Tz]Wrap a UTC naive datetime with the given time zone
    DateTime::unix_epoch()-> Self[Utc]The Unix epoch instant, 1970-01-01T00:00:00Z; also the Default for DateTime[Utc] (no other zone has a natural default)
    DateTime::from_local(NaiveDateTime, Tz) (Tz : TimeZone)-> MappedLocalTime[Self[Tz]]Build from a local (wall-clock) naive datetime, resolving DST ambiguity via tz.offset_from_local
    DateTime::from_local_lenient(NaiveDateTime, Tz) (Tz : TimeZone)-> Self[Tz]Like from_local but always succeeds: an unambiguous reading resolves exactly; a fold takes its first occurrence (as earliest()); a gap is read with the offset in effect just before the transition, landing after the gap by its length (02:30 in a 02:00-03:00 gap becomes 03:30)

    The lenient rule is the library's only policy for a local reading that is repeated or skipped, and the calendar steps use it too. Other choices come from from_local (.latest() for the later occurrence of a fold, .single() to reject both cases). To build one from components, use NaiveDateTime::from_ymd_hms(..) and then DateTime::from_local_lenient. | DateTime::from_ymd_hms(Int, Int, Int, Int, Int, Int, Tz) (Tz : TimeZone) | -> MappedLocalTime[Self[Tz]] | Build from local calendar/time-of-day components; Absent for an invalid date/time-of-day, in addition to the usual DST-gap case | | DateTime::from_timestamp(Int64, Int, Tz) | -> Self[Tz]? | Build from a Unix timestamp (seconds + nanoseconds) through the given time zone; always unambiguous, None only on an out-of-range input | | DateTime::from_timestamp_millis(Int64, Tz) / from_timestamp_micros / from_timestamp_nanos | -> Self[Tz]? | Build from a Unix timestamp in that unit through the given time zone; None if the instant is outside NaiveDate's range (reachable only for milliseconds at Int64 extremes) | | naive_utc() | -> NaiveDateTime | The underlying naive datetime, in UTC | | timezone() | -> Tz | The time zone value this datetime is expressed in | | offset() (Tz : TimeZone) | -> FixedOffset | The UTC offset in effect at this instant | | naive_local() (Tz : TimeZone) | -> NaiveDateTime | The UTC datetime shifted by offset() | | with_timezone(Tz2) | -> Self[Tz2] | Re-express this datetime in Tz2, keeping the same UTC instant | | to_utc() | -> Self[Utc] | Re-express the same instant in UTC | | fixed_offset() | -> Self[FixedOffset] | Re-express the same instant with the offset in effect at that instant frozen (requires Tz : TimeZone); it no longer follows later DST changes | | add_signed(TimeDelta) | -> Self[Tz] | Advance by a signed duration, keeping the same time zone | | sub_signed(TimeDelta) | -> Self[Tz] | Move back by a signed duration | | add_offset(FixedOffset) / sub_offset(FixedOffset) | -> Self[Tz] | Move the instant forward/backward by an offset's seconds (the opposite way for a west offset), keeping the same time zone; abort if the result leaves NaiveDate's range | | checked_add_offset(FixedOffset) / checked_sub_offset(FixedOffset) | -> Self[Tz]? | The same, but None instead of aborting when out of range | | add_months(Int) (Tz : TimeZone) | -> Self[Tz] | Advance the local date by months, keeping the local time of day and the time zone; see NaiveDate::add_months (in core) for the day-of-month clamping rule. A result in a DST fold takes the earlier occurrence and one in a gap moves forward by the gap's length, as from_local_lenient does | | sub_months(Int) | -> Self[Tz] | Move the date back by months | | add_years(Int) (Tz : TimeZone) | -> Self[Tz] | Advance the local date by years, keeping the local time of day and the time zone; see NaiveDate::add_years (in core) for the clamping rule | | sub_years(Int) | -> Self[Tz] | Move the date back by years | | add_days(Int) (Tz : TimeZone) | -> Self[Tz] | Advance the local date by days, keeping the local time of day and the time zone, so a day across a DST change lasts 23 or 25 hours; fold and gap as for add_months | | sub_days(Int) | -> Self[Tz] | Move the date back by days | | add_seconds(Int64) / sub_seconds(Int64) | -> Self[Tz] | Move the instant by a whole number of seconds (backward if negative), keeping the same time zone; abort if the result leaves NaiveDate's range | | checked_add_seconds(Int64) / checked_sub_seconds(Int64) | -> Self[Tz]? | The same, but None instead of aborting when out of range | | checked_add_signed(TimeDelta) / checked_sub_signed(TimeDelta) | -> Self[Tz]? | Like add_signed/sub_signed, but None instead of aborting when the result leaves NaiveDate's range | | checked_add_months(Int) / checked_sub_months(Int) / checked_add_years(Int) / checked_sub_years(Int) / checked_add_days(Int) / checked_sub_days(Int) | -> Self[Tz]? | Like the aborting forms above, but None instead of aborting when the date leaves NaiveDate's range | | date() / time() | -> NaiveDate / -> NaiveTime | The local calendar date / time of day | | year() / month() / day() / ordinal() / weekday() / iso_week() | -> Int / -> Month / -> Int / -> Int / -> Weekday / -> IsoWeek | Local calendar components, derived from naive_local() (requires Tz : TimeZone) | | ymd() / hms() | -> (Int, Month, Int) / (Int, Int, Int) | The local date and time components together | | leap_year() | -> Bool | Whether the local calendar year is a leap year | | hour() / minute() / second() / nanosecond() | -> Int | Local time-of-day components; a leap second reports second() == 59 with nanosecond() >= 1_000_000_000 | | month0() / day0() / ordinal0() / quarter() / num_days_in_month() / num_days_from_ce() | -> Int | Further local calendar components (0-based month/day/ordinal, quarter 1..=4, month length, days since the start of the Common Era) | | year_ce() / hour12() | -> YearCe / -> ClockHour12 | Local year as a Common Era flag plus a positive year; local hour as a PM flag plus an hour in 1..=12 (@core.YearCe, @core.ClockHour12) | | num_seconds_from_midnight() | -> Int | Seconds since local midnight | | with_year(Int) / with_month(Int) / with_day(Int) / with_ordinal(Int) / with_hour(Int) / with_minute(Int) / with_second(Int) / with_nanosecond(Int) | -> MappedLocalTime[Self[Tz]] | Replace one local component and re-resolve the wall-clock reading through the zone: Absent for an invalid value or a DST gap, Ambiguous inside a DST fold | | with_month0(Int) / with_day0(Int) / with_ordinal0(Int) | -> MappedLocalTime[Self[Tz]] | 0-based counterparts of with_month/with_day/with_ordinal, resolved the same way | | with_date(NaiveDate) | -> MappedLocalTime[Self[Tz]] | Replace the local date, keeping the local time of day; Absent inside a DST gap, Ambiguous inside a fold | | with_time(NaiveTime) | -> MappedLocalTime[Self[Tz]] | Replace the local time of day, keeping the local date, resolved the same way as the with_* setters | | timestamp() / timestamp_millis() | -> Int64 | Non-leap seconds / milliseconds since the Unix epoch, flooring toward negative infinity; independent of the zone | | timestamp_micros() / timestamp_nanos() | -> Int64? | Microseconds / nanoseconds since the Unix epoch; None if the instant overflows Int64 | | timestamp_subsec_nanos() / timestamp_subsec_millis() / timestamp_subsec_micros() | -> Int | The sub-second component of the instant in that unit | | signed_duration_since(Self[Tz2]) | -> TimeDelta | The signed duration from other to self, independent of either's time zone | | zone_name() | -> String | The zone's name at this instant: an IANA abbreviation ("EDT"), a FixedZone's name, "UTC", or a bare FixedOffset's offset text; the same text as %Z (requires Tz : TimeZone) | | is_dst() | -> Bool | Whether daylight saving time is in effect at this instant (requires Tz : TimeZone) | | zone_bounds() | -> TransitionBounds | The validity window of the offset in effect at this instant, either side None when unbounded (requires Tz : TimeZone); see TransitionBounds | | to_string() (Show) | -> String | The local date-time and the zone's name at that instant joined by a space, e.g. "2024-01-02 13:45:06.500 +09:00", "... UTC", "... EDT" (requires Tz : TimeZone) | | years_since(Self[Tz2]) | -> Int? | Full calendar years elapsed from base (which may be in another time zone), reading both as local dates in the receiver's time zone and ignoring the time of day; None if base is later | | compare(Self[Tz]) / < / > / <= / >= | -> Int / -> Bool | Order by UTC instant, ignoring the zone value; consistent with == | | compare_instant(Self[Tz2]) | -> Int | Order by UTC instant against a datetime in a different time zone type | | round(TimeDelta) | -> Result[Self[Tz], @core.RoundingError] | Round the underlying UTC instant to the nearest multiple of a granularity since the Unix epoch, keeping the same time zone; see TimeDelta::round (in core) for which granularities are supported | | round_up(TimeDelta) | -> Result[Self[Tz], @core.RoundingError] | Round the underlying UTC instant up (toward positive infinity) to the next multiple of a granularity since the Unix epoch, unchanged if already a multiple, keeping the same time zone; see NaiveDateTime::round_up for the failure reasons | | truncate(TimeDelta) | -> Result[Self[Tz], @core.RoundingError] | Truncate the underlying UTC instant toward the Unix epoch; see Quick start above for how this differs from truncating the local presentation | | round_subsecs(Int) / truncate_subsecs(Int) | -> Result[Self[Tz], @core.RoundingError] / -> Self[Tz] | Round or truncate the underlying UTC instant to a number of fractional-second digits (0..=9; other values abort) |

    Rounding acts on the UTC instant, not the local reading, so in a zone such as +05:30 a one-hour truncation leaves a local time that is not on the hour. To round to a local boundary, round naive_local() and resolve the result with DateTime::from_local. Calendar steps (add_days, add_months, add_years) act on the local reading, while add_signed, add_seconds and the rounding methods act on the instant.

    DateTime[Tz] also implements Eq (when Tz : Eq).


    #Location

    A time zone backed by parsed IANA tzdata (TZif binary format, plus a POSIX TZ string for extrapolating past the last recorded transition).

    MethodSignatureDescription
    Location::load(String)-> Self?Look up an embedded IANA zone by name (e.g. "Asia/Tokyo"), following aliases; None if the name is unknown, including the empty string (which is not an alias for UTC); "UTC" resolves like any other zone
    Location::utc()-> SelfThe UTC zone as a Location (equal to Location::load("UTC"), name() is Some("UTC")), for APIs taking a Location rather than the separate Utc type
    Location::from_tzif_bytes(Bytes)-> Self?Parse a zone directly from raw TZif bytes; None if malformed
    Location::from_tzif_bytes_named(String, Bytes)-> Self?Like from_tzif_bytes, but name() reports the given name; any text is accepted as given, without validation
    name()-> String?The IANA identifier this Location was loaded with (the name as given to Location::load, not canonicalized through an alias); None for one built via from_tzif_bytes
    to_string() (Show)-> Stringname(), or an empty string for a Location without one
    offset_from_abbreviation(String, NaiveDateTime)-> FixedOffset?The offset an abbreviation (e.g. "EST") denotes: that of the type in effect at the given UTC instant if it matches, else of the first type in the zone's table with that abbreviation; None if none has it
    type_at(NaiveDateTime)-> LocalTimeTypeThe offset, DST flag, and abbreviation in effect at a given UTC instant
    offset_from_utc(NaiveDateTime)-> FixedOffsetThe offset in effect at a given UTC instant
    offset_from_local(NaiveDateTime)-> MappedLocalTime[FixedOffset]The offset(s) for a given local instant, resolving DST folds and gaps
    zone_name(NaiveDateTime)-> StringThe abbreviation in effect at a given instant, e.g. "EDT"
    transition_bounds(NaiveDateTime)-> TransitionBoundsThe validity window of the segment covering a given instant; see TransitionBounds

    Location also implements TimeZone. == is structural: two Locations are equal when their parsed TZif data, POSIX rule and name() all match, so an alias (e.g. "Japan") is unequal to its canonical zone ("Asia/Tokyo") even though both resolve identically.

    #TransitionBounds

    The validity window of a Location's segment covering a given instant, as returned by Location::transition_bounds: the local time type type_at reports is in effect from start() (inclusive) until end() (exclusive). None on either side means unbounded in that direction.

    MethodSignatureDescription
    start()-> NaiveDateTime?The instant this segment began; None if unbounded (before the zone's first recorded transition, or for a zone with no transitions at all)
    end()-> NaiveDateTime?The instant the next segment begins; None if unbounded (past the zone's last recorded transition, when no POSIX rule extrapolates further)

    Past the last recorded transition, the POSIX rule's own bounds are computed exactly (not approximated near a year boundary).

    TransitionBounds also implements Eq.

    #LocalTimeType

    The offset, DST flag, and abbreviation for one segment of a Location's timeline, as returned by Location::type_at.

    MethodSignatureDescription
    LocalTimeType::new(Int, Bool, String)-> Self?Construct from UTC offset (seconds), DST flag, and abbreviation; None if the offset is outside ±86399 (±23:59:59), so every LocalTimeType has an offset a FixedOffset can hold
    utc_offset()-> IntUTC offset in seconds
    is_dst()-> BoolWhether daylight saving is in effect
    abbreviation()-> StringThe zone abbreviation, e.g. "EST"/"EDT"

    LocalTimeType also implements Eq.

    #Local (native only)

    The OS-configured local time zone, resolved from $TZ or, when unset, /etc/localtime. Only compiled for the native backend: resolving it requires file I/O that js/wasm/wasm-gc have no host-provided access to. The generated .mbti of the default target (wasm) therefore omits Local; its native interface (Local::new, Local::now and the TimeZone methods) is the one to review for a release. The one place the host environment is read is Local::new; the rule it applies to $TZ and /etc/localtime is internal and not public API.

    MethodSignatureDescription
    Local::new()-> Self?Resolves the host's configured time zone; None if it could not be determined. Reads live OS state — not a pure function of its arguments.
    Local::now()-> DateTime[Local]?The current instant in the host's local zone, the counterpart of Utc::now(); None when Local::new() is None, that is, when the zone cannot be determined; the clock itself is read as in Utc::now()
    offset_from_utc(NaiveDateTime)-> FixedOffsetDelegates to the resolved zone
    offset_from_local(NaiveDateTime)-> MappedLocalTime[FixedOffset]Delegates to the resolved zone
    zone_name(NaiveDateTime)-> StringDelegates to the resolved zone

    Local also implements TimeZone. $TZ may be an IANA zone name, an empty string (UTC), or a bare POSIX TZ rule such as "JST-9" or "FOO5BAR4,M3.2.0,M11.1.0"; an IANA name takes precedence when a string is both (e.g. "EST5EDT"). The leading-colon form (":Asia/Tokyo") is not handled.


    #Advanced: low-level TZif and POSIX TZ parsing

    Failure is reported as None throughout this package (parse_tzif, parse_posix_tz, Location::from_tzif_bytes, Location::from_tzif_bytes_named, Location::load), unlike format, whose parsers raise a FormatError naming the reason. These read machine data (TZif bytes, POSIX TZ strings, zone names), where a caller's response to any failure is the same, so no reason is carried; each function's documentation lists the conditions under which it returns None (a malformed structure, an offset beyond ±23:59:59, or an unknown zone name).

    These back Location and are not usually needed directly; use Location::load/from_tzif_bytes unless building a custom zone-data pipeline.

    SymbolSignatureDescription
    parse_tzif(Bytes)-> TzifData?Parse raw TZif bytes (header, transition table, local-time-type table, leap seconds, POSIX TZ footer)
    parse_posix_tz(String)-> PosixTz?Parse a POSIX TZ rule string (all three date-rule forms: Jn, n, Mm.w.d)

    TypeKey methodsDescription
    TzifDatatransitions(), transition_types(), local_time_types(), leap_seconds(), posix_tz()The parsed contents of a TZif file; the array accessors return copies, and posix_tz() is the already-parsed PosixTz? footer (None when empty or absent; a malformed one makes parse_tzif return None)
    PosixTztype_at(NaiveDateTime) (a UTC reading, like Location::type_at), offset_from_local(NaiveDateTime)An evaluated POSIX TZ rule, for extrapolating past a TZif file's last recorded transition; also a TimeZone in its own right (a constant offset when the rule has no DST part, e.g. JST-9)

    TimeZone

    A time zone: given a naive datetime, resolves it to a concrete UTC offset.

    The trait is readonly: code outside this package can use it as a bound but cannot implement it, so the zones are the ones this package provides (Utc, FixedOffset, FixedZone, Location, PosixTz and, on native, Local).

    Every NaiveDateTime argument is a UTC reading except the one taken by offset_from_local, which is a local (wall-clock) reading; the type does not distinguish them, so pass DateTime::naive_utc for the former and DateTime::naive_local for the latter.

    DateTime

    pub struct DateTime[Tz] {
    // private fields
    } derive(
    Debug
    )

    A datetime with an associated time zone.

    Internally stores the UTC naive datetime plus the zone value tz; the local (wall-clock) representation is derived on demand via tz.offset_from_utc, never stored redundantly.

    Identity is the UTC instant: Eq, Hash and Compare all ignore the zone value, so the same instant expressed in different zones is equal, hashes alike and compares as 0.
    impl Compare for DateTime[Tz]
    impl Default for DateTime[Utc]
    impl Eq for DateTime[Tz]
    impl Hash for DateTime[Tz]
    impl Show for DateTime[Tz]

    DateTime::add_days

    fn[Tz : TimeZone] DateTime::add_days(self : DateTime[Tz], days : Int) -> DateTime[Tz]

    This datetime with its local date advanced by days (or moved back, if days is negative), keeping the local time of day and the time zone, so a day across a DST change is 23 or 25 hours long. See add_months for how a DST gap or fold is resolved.

    Aborts if the result falls outside NaiveDate's representable range; use checked_add_days to get None instead.

    DateTime::add_months

    fn[Tz : TimeZone] DateTime::add_months(self : DateTime[Tz], months : Int) -> DateTime[Tz]

    This datetime with its local date advanced by months (or moved back, if months is negative), keeping the local time of day and the time zone. See @core.NaiveDateTime::add_months for the day-of-month clamping rule. A result that falls in a DST fold takes the earlier occurrence, and one in a gap moves forward by the gap's length, as from_local_lenient does.

    Aborts if the result falls outside NaiveDate's representable range; use checked_add_months to get None instead.

    DateTime::add_offset

    fn[Tz] DateTime::add_offset(self : DateTime[Tz], offset : FixedOffset) -> DateTime[Tz]

    This datetime's instant moved forward by offset's seconds (backward for a west offset), keeping the same time zone. Delegates to @core.NaiveDateTime::add_seconds on the underlying UTC datetime.

    Aborts if the result falls outside NaiveDate's representable range; use checked_add_offset to get None instead.

    DateTime::add_seconds

    fn[Tz] DateTime::add_seconds(self : DateTime[Tz], seconds : Int64) -> DateTime[Tz]

    This datetime's instant moved forward by seconds (backward if negative), keeping the same time zone.

    Aborts if the result falls outside NaiveDate's representable range; use checked_add_seconds to get None instead.

    DateTime::add_signed

    fn[Tz] DateTime::add_signed(self : DateTime[Tz], delta :
    TimeDelta
    ) -> DateTime[Tz]

    This datetime advanced by the signed duration delta, keeping the same time zone. Delegates to NaiveDateTime::add_signed on the underlying UTC instant.

    Aborts if the result falls outside NaiveDate's representable range; use checked_add_signed to get None instead.

    DateTime::add_years

    fn[Tz : TimeZone] DateTime::add_years(self : DateTime[Tz], years : Int) -> DateTime[Tz]

    This datetime with its local date advanced by years (or moved back, if years is negative), keeping the local time of day and the time zone. See @core.NaiveDate::add_years for the day-of-month clamping rule, and add_months for how a DST gap or fold is resolved.

    Aborts if the result falls outside NaiveDate's representable range; use checked_add_years to get None instead.

    DateTime::checked_add_days

    fn[Tz : TimeZone] DateTime::checked_add_days(self : DateTime[Tz], days : Int) -> DateTime[Tz]?

    Like add_days, but None if the result falls outside NaiveDate's representable range.

    DateTime::checked_add_months

    fn[Tz : TimeZone] DateTime::checked_add_months(self : DateTime[Tz], months : Int) -> DateTime[Tz]?

    Like add_months, but None if the result falls outside NaiveDate's representable range.

    DateTime::checked_add_offset

    fn[Tz] DateTime::checked_add_offset(self : DateTime[Tz], offset : FixedOffset) -> DateTime[Tz]?

    Like add_offset, but None if the result falls outside NaiveDate's representable range.

    DateTime::checked_add_seconds

    fn[Tz] DateTime::checked_add_seconds(self : DateTime[Tz], seconds : Int64) -> DateTime[Tz]?

    Like add_seconds, but None if the result falls outside NaiveDate's representable range.

    DateTime::checked_add_signed

    fn[Tz] DateTime::checked_add_signed(self : DateTime[Tz], delta :
    TimeDelta
    ) -> DateTime[Tz]?

    Like add_signed, but None if the result falls outside NaiveDate's representable range.

    DateTime::checked_add_years

    fn[Tz : TimeZone] DateTime::checked_add_years(self : DateTime[Tz], years : Int) -> DateTime[Tz]?

    Like add_years, but None if the result falls outside NaiveDate's representable range.

    DateTime::checked_sub_days

    fn[Tz : TimeZone] DateTime::checked_sub_days(self : DateTime[Tz], days : Int) -> DateTime[Tz]?

    Like sub_days, but None if the result falls outside NaiveDate's representable range.

    DateTime::checked_sub_months

    fn[Tz : TimeZone] DateTime::checked_sub_months(self : DateTime[Tz], months : Int) -> DateTime[Tz]?

    Like sub_months, but None if the result falls outside NaiveDate's representable range.

    DateTime::checked_sub_offset

    fn[Tz] DateTime::checked_sub_offset(self : DateTime[Tz], offset : FixedOffset) -> DateTime[Tz]?

    Like sub_offset, but None if the result falls outside NaiveDate's representable range.

    DateTime::checked_sub_seconds

    fn[Tz] DateTime::checked_sub_seconds(self : DateTime[Tz], seconds : Int64) -> DateTime[Tz]?

    Like sub_seconds, but None if the result falls outside NaiveDate's representable range.

    DateTime::checked_sub_signed

    fn[Tz] DateTime::checked_sub_signed(self : DateTime[Tz], delta :
    TimeDelta
    ) -> DateTime[Tz]?

    Like sub_signed, but None if the result falls outside NaiveDate's representable range.

    DateTime::checked_sub_years

    fn[Tz : TimeZone] DateTime::checked_sub_years(self : DateTime[Tz], years : Int) -> DateTime[Tz]?

    Like sub_years, but None if the result falls outside NaiveDate's representable range.

    DateTime::compare

    fn[Tz] DateTime::compare(self : DateTime[Tz], other : DateTime[Tz]) -> Int

    DateTime::compare_instant

    fn[Tz, Tz2] DateTime::compare_instant(self : DateTime[Tz], other : DateTime[Tz2]) -> Int

    Orders this datetime against one in a possibly different time zone type, by UTC instant alone: -1 if self is earlier, 0 if both are the same instant, 1 if self is later.

    DateTime::date

    The local calendar date.

    DateTime::day

    fn[Tz : TimeZone] DateTime::day(self : DateTime[Tz]) -> Int

    The local day of the month, 1..=31.

    DateTime::day0

    fn[Tz : TimeZone] DateTime::day0(self : DateTime[Tz]) -> Int

    The local day of the month, counting from 0.

    DateTime::default

    fn DateTime::default() -> DateTime[Utc]

    DateTime::equal

    fn[Tz] DateTime::equal(self : DateTime[Tz], other : DateTime[Tz]) -> Bool

    DateTime::fixed_offset

    fn[Tz : TimeZone] DateTime::fixed_offset(self : DateTime[Tz]) -> DateTime[FixedOffset]

    This datetime re-expressed with a fixed offset equal to the one in effect at its instant, keeping the same underlying instant. The result no longer follows the original zone's later offset changes (e.g. DST transitions).

    DateTime::from_local

    Builds a DateTime[Tz] from a local (wall-clock) naive datetime and a time zone, resolving DST ambiguity via tz.offset_from_local: Single for an unambiguous reading, Ambiguous(earliest, latest) within a fall-back fold, or Absent within a spring-forward gap.

    DateTime::from_local_lenient

    fn[Tz : TimeZone] DateTime::from_local_lenient(naive_local :
    NaiveDateTime
    , tz : Tz) -> DateTime[Tz]

    Builds a DateTime[Tz] from a local (wall-clock) naive datetime and a time zone, always succeeding: unlike from_local, no reading is left unresolved.

    • An unambiguous reading resolves exactly as from_local does.
    • A reading repeated by a fall-back fold takes its first occurrence (the earlier UTC instant), as MappedLocalTime::earliest does.
    • A reading skipped by a spring-forward gap is interpreted with the offset in effect just before the transition, so the result lands after the gap by the gap's length (e.g. 02:30 in a gap from 02:00 to 03:00 becomes 03:30).

    A zone that reports a gap but exposes no transition bounds to find the earlier offset from resolves the reading with its offset at that reading taken as a UTC instant.

    This is the single policy of the library, also used by the calendar steps (add_days and the like). For another choice, resolve with from_local and pick from the result: .latest() takes the later occurrence of a fold, and .single() rejects both a fold and a gap. To build one from components, go through NaiveDateTime::from_ymd_hms.

    DateTime::from_timestamp

    fn[Tz] DateTime::from_timestamp(secs : Int64, nanos : Int, tz : Tz) -> DateTime[Tz]?

    Builds a DateTime[Tz] from the number of non-leap seconds since the Unix epoch plus a nanosecond component, and a time zone. Always unambiguous (a UTC instant, unlike from_local): None only when secs/nanos themselves are out of range — see @core.NaiveDateTime::from_timestamp.

    DateTime::from_timestamp_micros

    fn[Tz] DateTime::from_timestamp_micros(micros : Int64, tz : Tz) -> DateTime[Tz]?

    Builds a DateTime[Tz] from the number of non-leap microseconds since the Unix epoch and a time zone; see from_timestamp. None if the instant is outside NaiveDate's representable range.

    DateTime::from_timestamp_millis

    fn[Tz] DateTime::from_timestamp_millis(millis : Int64, tz : Tz) -> DateTime[Tz]?

    Builds a DateTime[Tz] from the number of non-leap milliseconds since the Unix epoch and a time zone; see from_timestamp. None if the instant is outside NaiveDate's representable range.

    DateTime::from_timestamp_nanos

    fn[Tz] DateTime::from_timestamp_nanos(nanos : Int64, tz : Tz) -> DateTime[Tz]?

    Builds a DateTime[Tz] from the number of non-leap nanoseconds since the Unix epoch and a time zone; see from_timestamp. None if the instant is outside NaiveDate's representable range.

    DateTime::from_utc

    fn[Tz] DateTime::from_utc(datetime :
    NaiveDateTime
    , tz : Tz) -> DateTime[Tz]

    Wraps a UTC naive datetime with the given time zone.

    DateTime::from_ymd_hms

    fn[Tz : TimeZone] DateTime::from_ymd_hms(year : Int, month : Int, day : Int, hour : Int, min : Int, sec : Int, tz : Tz) -> MappedLocalTime[DateTime[Tz]]

    Builds a DateTime[Tz] from local calendar/time-of-day components and a time zone (the proleptic Gregorian calendar, year 0 being 1 BCE). Absent for an invalid date or time-of-day, in addition to the usual DST-gap case — see from_local.

    DateTime::hash

    fn[Tz] DateTime::hash(self : DateTime[Tz]) -> Int

    DateTime::hash_combine

    fn[Tz] DateTime::hash_combine(self : DateTime[Tz], hasher : Hasher) -> Unit

    DateTime::hms

    fn[Tz : TimeZone] DateTime::hms(self : DateTime[Tz]) -> (Int, Int, Int)

    The local hour, minute, and second together.

    DateTime::hour

    fn[Tz : TimeZone] DateTime::hour(self : DateTime[Tz]) -> Int

    The local hour, 0..=23.

    DateTime::hour12

    The local hour on a 12-hour clock as a PM flag and an hour in 1..=12.

    DateTime::is_dst

    fn[Tz : TimeZone] DateTime::is_dst(self : DateTime[Tz]) -> Bool

    Whether daylight saving time is in effect at this instant, according to the time zone.

    DateTime::iso_week

    The local ISO 8601 week.

    DateTime::leap_year

    fn[Tz : TimeZone] DateTime::leap_year(self : DateTime[Tz]) -> Bool

    Whether the local calendar year is a leap year.

    DateTime::minute

    fn[Tz : TimeZone] DateTime::minute(self : DateTime[Tz]) -> Int

    The local minute, 0..=59.

    DateTime::month

    The local month.

    DateTime::month0

    fn[Tz : TimeZone] DateTime::month0(self : DateTime[Tz]) -> Int

    The local month, counting from 0.

    DateTime::naive_local

    The naive local (wall-clock) datetime, i.e. the UTC datetime shifted by offset(). Always succeeds: an offset is at most ±23:59:59, far within TimeDelta's representable range.

    DateTime::naive_utc

    The underlying naive datetime, in UTC.

    DateTime::nanosecond

    fn[Tz : TimeZone] DateTime::nanosecond(self : DateTime[Tz]) -> Int

    The local nanosecond within the second, 0..=1_999_999_999.

    DateTime::not_equal

    fn[Tz] DateTime::not_equal(x : DateTime[Tz], y : DateTime[Tz]) -> Bool

    DateTime::num_days_from_ce

    fn[Tz : TimeZone] DateTime::num_days_from_ce(self : DateTime[Tz]) -> Int

    The number of days from the start of the Common Era to the local date, counting 0001-01-01 as day 1.

    DateTime::num_days_in_month

    fn[Tz : TimeZone] DateTime::num_days_in_month(self : DateTime[Tz]) -> Int

    The number of days in the local month.

    DateTime::num_seconds_from_midnight

    fn[Tz : TimeZone] DateTime::num_seconds_from_midnight(self : DateTime[Tz]) -> Int

    The number of seconds since local midnight.

    DateTime::offset

    fn[Tz : TimeZone] DateTime::offset(self : DateTime[Tz]) -> FixedOffset

    The UTC offset in effect at this instant.

    DateTime::op_ge

    fn[Tz] DateTime::op_ge(x : DateTime[Tz], y : DateTime[Tz]) -> Bool

    DateTime::op_gt

    fn[Tz] DateTime::op_gt(x : DateTime[Tz], y : DateTime[Tz]) -> Bool

    DateTime::op_le

    fn[Tz] DateTime::op_le(x : DateTime[Tz], y : DateTime[Tz]) -> Bool

    DateTime::op_lt

    fn[Tz] DateTime::op_lt(x : DateTime[Tz], y : DateTime[Tz]) -> Bool

    DateTime::ordinal

    fn[Tz : TimeZone] DateTime::ordinal(self : DateTime[Tz]) -> Int

    The local day of the year, 1..=366.

    DateTime::ordinal0

    fn[Tz : TimeZone] DateTime::ordinal0(self : DateTime[Tz]) -> Int

    The local day of the year, counting from 0.

    DateTime::output

    fn[Tz : TimeZone] DateTime::output(self : DateTime[Tz], logger : &Logger) -> Unit

    DateTime::quarter

    fn[Tz : TimeZone] DateTime::quarter(self : DateTime[Tz]) -> Int

    The local quarter of the year, 1..=4.

    DateTime::round

    This datetime's underlying UTC instant rounded to the nearest multiple of granularity since the Unix epoch, ties breaking away from the epoch, keeping the same time zone. Like truncate, it operates on the absolute UTC instant rather than the local presentation; to round to a local boundary, round naive_local() and use DateTime::from_local.

    DateTime::round_subsecs

    fn[Tz] DateTime::round_subsecs(self : DateTime[Tz], digits : Int) -> Result[DateTime[Tz],
    RoundingError
    ]

    This datetime's underlying UTC instant rounded to digits fractional-second digits (0..=9), keeping the same time zone. See @core.NaiveDateTime::round_subsecs; aborts if digits is outside 0..=9.

    DateTime::round_up

    This datetime's underlying UTC instant rounded up (toward positive infinity) to the nearest multiple of granularity since the Unix epoch: unchanged if already a multiple, otherwise the next one after it, keeping the same time zone. Like truncate, it operates on the absolute UTC instant rather than the local presentation. See @core.NaiveDateTime::round_up for the failure reasons.

    DateTime::second

    fn[Tz : TimeZone] DateTime::second(self : DateTime[Tz]) -> Int

    The local second, 0..=59; a leap second reports 59 with nanosecond() at or above 1_000_000_000.

    DateTime::signed_duration_since

    fn[Tz, Tz2] DateTime::signed_duration_since(self : DateTime[Tz], other : DateTime[Tz2]) ->
    TimeDelta

    The signed duration from other to self (positive if self is later), independent of either datetime's time zone (both are compared via their underlying UTC instant).

    DateTime::sub_days

    fn[Tz : TimeZone] DateTime::sub_days(self : DateTime[Tz], days : Int) -> DateTime[Tz]

    This datetime with its local date moved back by days. See add_days.

    Aborts if the result falls outside NaiveDate's representable range; use checked_sub_days to get None instead.

    DateTime::sub_months

    fn[Tz : TimeZone] DateTime::sub_months(self : DateTime[Tz], months : Int) -> DateTime[Tz]

    This datetime with its local date moved back by months. See add_months.

    Aborts if the result falls outside NaiveDate's representable range; use checked_sub_months to get None instead.

    DateTime::sub_offset

    fn[Tz] DateTime::sub_offset(self : DateTime[Tz], offset : FixedOffset) -> DateTime[Tz]

    This datetime's instant moved backward by offset's seconds (forward for a west offset), keeping the same time zone. See add_offset.

    Aborts if the result falls outside NaiveDate's representable range; use checked_sub_offset to get None instead.

    DateTime::sub_seconds

    fn[Tz] DateTime::sub_seconds(self : DateTime[Tz], seconds : Int64) -> DateTime[Tz]

    This datetime's instant moved backward by seconds (forward if negative). See add_seconds.

    Aborts if the result falls outside NaiveDate's representable range; use checked_sub_seconds to get None instead.

    DateTime::sub_signed

    fn[Tz] DateTime::sub_signed(self : DateTime[Tz], delta :
    TimeDelta
    ) -> DateTime[Tz]

    This datetime moved back by the signed duration delta. See add_signed.

    Aborts if the result falls outside NaiveDate's representable range; use checked_sub_signed to get None instead.

    DateTime::sub_years

    fn[Tz : TimeZone] DateTime::sub_years(self : DateTime[Tz], years : Int) -> DateTime[Tz]

    This datetime with its local date moved back by years. See add_years.

    Aborts if the result falls outside NaiveDate's representable range; use checked_sub_years to get None instead.

    DateTime::time

    The local time of day.

    DateTime::timestamp

    fn[Tz] DateTime::timestamp(self : DateTime[Tz]) -> Int64

    The number of non-leap seconds since the Unix epoch, flooring toward negative infinity. Independent of the time zone.

    DateTime::timestamp_micros

    fn[Tz] DateTime::timestamp_micros(self : DateTime[Tz]) -> Int64?

    The number of non-leap microseconds since the Unix epoch; None if it overflows Int64. Independent of the time zone.

    DateTime::timestamp_millis

    fn[Tz] DateTime::timestamp_millis(self : DateTime[Tz]) -> Int64

    The number of non-leap milliseconds since the Unix epoch. Independent of the time zone.

    DateTime::timestamp_nanos

    fn[Tz] DateTime::timestamp_nanos(self : DateTime[Tz]) -> Int64?

    The number of non-leap nanoseconds since the Unix epoch; None if it overflows Int64. Independent of the time zone.

    DateTime::timestamp_subsec_micros

    fn[Tz] DateTime::timestamp_subsec_micros(self : DateTime[Tz]) -> Int

    The microsecond component of the instant within its second. Independent of the time zone.

    DateTime::timestamp_subsec_millis

    fn[Tz] DateTime::timestamp_subsec_millis(self : DateTime[Tz]) -> Int

    The millisecond component of the instant within its second. Independent of the time zone.

    DateTime::timestamp_subsec_nanos

    fn[Tz] DateTime::timestamp_subsec_nanos(self : DateTime[Tz]) -> Int

    The nanosecond component of the instant within its second. Independent of the time zone.

    DateTime::timezone

    fn[Tz] DateTime::timezone(self : DateTime[Tz]) -> Tz

    The time zone this datetime is expressed in.

    DateTime::to_string

    fn[Tz : TimeZone] DateTime::to_string(self : DateTime[Tz]) -> String

    DateTime::to_utc

    fn[Tz] DateTime::to_utc(self : DateTime[Tz]) -> DateTime[Utc]

    This datetime re-expressed in UTC, keeping the same underlying instant.

    DateTime::truncate

    This datetime's underlying UTC instant truncated toward the Unix epoch to the nearest multiple of granularity, keeping the same time zone. Operates on the absolute UTC instant, not the offset-shifted local presentation: truncating to an hour granularity may still report a non-zero local minute, depending on the time zone's offset. See @core.NaiveDateTime::truncate for the conditions under which granularity is rejected.

    DateTime::truncate_subsecs

    fn[Tz] DateTime::truncate_subsecs(self : DateTime[Tz], digits : Int) -> DateTime[Tz]

    This datetime's underlying UTC instant truncated to digits fractional-second digits (0..=9), keeping the same time zone. See @core.NaiveDateTime::truncate_subsecs; aborts if digits is outside 0..=9.

    DateTime::unix_epoch

    fn DateTime::unix_epoch() -> DateTime[Utc]

    The Unix epoch instant, 1970-01-01T00:00:00Z: timestamp zero, in UTC. Default::default() returns it.

    DateTime::weekday

    The local day of the week.

    DateTime::with_date

    This datetime with its local date replaced by date, keeping the local time of day and re-resolving the wall-clock reading through the time zone: Absent inside a DST gap, Ambiguous inside a DST fold.

    DateTime::with_day

    fn[Tz : TimeZone] DateTime::with_day(self : DateTime[Tz], day : Int) -> MappedLocalTime[DateTime[Tz]]

    This datetime with the local day of the month replaced, keeping the rest of the local wall-clock reading and re-resolving it through the time zone: Absent for a value that does not form a valid local reading (see @core.NaiveDateTime::with_day) or a reading inside a DST gap, and Ambiguous inside a DST fold.

    DateTime::with_day0

    fn[Tz : TimeZone] DateTime::with_day0(self : DateTime[Tz], day0 : Int) -> MappedLocalTime[DateTime[Tz]]

    Like with_day, but taking the local day of the month counting from 0.

    DateTime::with_hour

    fn[Tz : TimeZone] DateTime::with_hour(self : DateTime[Tz], hour : Int) -> MappedLocalTime[DateTime[Tz]]

    This datetime with the local hour replaced, keeping the rest of the local wall-clock reading and re-resolving it through the time zone: Absent for a value that does not form a valid local reading (see @core.NaiveDateTime::with_hour) or a reading inside a DST gap, and Ambiguous inside a DST fold.

    DateTime::with_minute

    fn[Tz : TimeZone] DateTime::with_minute(self : DateTime[Tz], minute : Int) -> MappedLocalTime[DateTime[Tz]]

    This datetime with the local minute replaced, keeping the rest of the local wall-clock reading and re-resolving it through the time zone: Absent for a value that does not form a valid local reading (see @core.NaiveDateTime::with_minute) or a reading inside a DST gap, and Ambiguous inside a DST fold.

    DateTime::with_month

    fn[Tz : TimeZone] DateTime::with_month(self : DateTime[Tz], month : Int) -> MappedLocalTime[DateTime[Tz]]

    This datetime with the local month (1..=12) replaced, keeping the rest of the local wall-clock reading and re-resolving it through the time zone: Absent for a value that does not form a valid local reading (see @core.NaiveDateTime::with_month) or a reading inside a DST gap, and Ambiguous inside a DST fold.

    DateTime::with_month0

    fn[Tz : TimeZone] DateTime::with_month0(self : DateTime[Tz], month0 : Int) -> MappedLocalTime[DateTime[Tz]]

    Like with_month, but taking the local month counting from 0.

    DateTime::with_nanosecond

    fn[Tz : TimeZone] DateTime::with_nanosecond(self : DateTime[Tz], nanosecond : Int) -> MappedLocalTime[DateTime[Tz]]

    This datetime with the local nanosecond replaced, keeping the rest of the local wall-clock reading and re-resolving it through the time zone: Absent for a value that does not form a valid local reading (see @core.NaiveDateTime::with_nanosecond) or a reading inside a DST gap, and Ambiguous inside a DST fold.

    DateTime::with_ordinal

    fn[Tz : TimeZone] DateTime::with_ordinal(self : DateTime[Tz], ordinal : Int) -> MappedLocalTime[DateTime[Tz]]

    This datetime with the local day of the year replaced, keeping the rest of the local wall-clock reading and re-resolving it through the time zone: Absent for a value that does not form a valid local reading (see @core.NaiveDateTime::with_ordinal) or a reading inside a DST gap, and Ambiguous inside a DST fold.

    DateTime::with_ordinal0

    fn[Tz : TimeZone] DateTime::with_ordinal0(self : DateTime[Tz], ordinal0 : Int) -> MappedLocalTime[DateTime[Tz]]

    Like with_ordinal, but taking the local day of the year counting from 0.

    DateTime::with_second

    fn[Tz : TimeZone] DateTime::with_second(self : DateTime[Tz], second : Int) -> MappedLocalTime[DateTime[Tz]]

    This datetime with the local second replaced, keeping the rest of the local wall-clock reading and re-resolving it through the time zone: Absent for a value that does not form a valid local reading (see @core.NaiveDateTime::with_second) or a reading inside a DST gap, and Ambiguous inside a DST fold.

    DateTime::with_time

    This datetime with its local time of day replaced by time, keeping the local date and re-resolving the wall-clock reading through the time zone: Absent inside a DST gap, Ambiguous inside a DST fold.

    DateTime::with_timezone

    fn[Tz, Tz2] DateTime::with_timezone(self : DateTime[Tz], tz : Tz2) -> DateTime[Tz2]

    This datetime re-expressed in tz, keeping the same underlying UTC instant.

    DateTime::with_year

    fn[Tz : TimeZone] DateTime::with_year(self : DateTime[Tz], year : Int) -> MappedLocalTime[DateTime[Tz]]

    This datetime with the local calendar year replaced, keeping the rest of the local wall-clock reading and re-resolving it through the time zone: Absent for a value that does not form a valid local reading (see @core.NaiveDateTime::with_year) or a reading inside a DST gap, and Ambiguous inside a DST fold.

    DateTime::year

    fn[Tz : TimeZone] DateTime::year(self : DateTime[Tz]) -> Int

    The local calendar year (proleptic Gregorian, year 0 being 1 BCE).

    DateTime::year_ce

    The local year as a Common Era flag and a positive year number. See @core.NaiveDate::year_ce.

    DateTime::years_since

    fn[Tz : TimeZone, Tz2] DateTime::years_since(self : DateTime[Tz], base : DateTime[Tz2]) -> Int?

    The number of full calendar years elapsed from base to this datetime, or None if base is later. base may be in a different time zone; both are read as local dates in this datetime's time zone, ignoring the time of day. See @core.NaiveDate::years_since.

    DateTime::ymd

    fn[Tz : TimeZone] DateTime::ymd(self : DateTime[Tz]) -> (Int,
    Month
    , Int)

    The local year, month, and day of month together.

    DateTime::zone_bounds

    fn[Tz : TimeZone] DateTime::zone_bounds(self : DateTime[Tz]) -> TransitionBounds

    The validity window of the offset in effect at this instant: from the transition that began it until the next one, either side None when unbounded. See TransitionBounds.

    DateTime::zone_name

    fn[Tz : TimeZone] DateTime::zone_name(self : DateTime[Tz]) -> String

    The name of the zone in effect at this instant: an IANA zone's abbreviation (e.g. "EDT"), a FixedZone's name, "UTC", or a bare FixedOffset's offset text. The same text as %Z and the end of Show.

    FixedOffset

    pub struct FixedOffset {
    // private fields
    } derive(Eq, Hash,
    Debug
    )

    A fixed UTC offset, constant year-round (no daylight saving).

    Represented as the signed number of seconds added to UTC to obtain the local time, within ±23:59:59 (±86399 seconds).
    impl Show for FixedOffset

    FixedOffset::east

    fn FixedOffset::east(secs : Int) -> FixedOffset?

    The fixed offset secs seconds east of UTC (local time is ahead of UTC), or None if secs is outside ±86399 (±23:59:59).

    FixedOffset::equal

    fn FixedOffset::equal(FixedOffset, FixedOffset) -> Bool

    FixedOffset::hash

    fn FixedOffset::hash(self : FixedOffset) -> Int

    FixedOffset::hash_combine

    fn FixedOffset::hash_combine(FixedOffset, Hasher) -> Unit

    FixedOffset::is_dst

    FixedOffset::local_minus_utc

    fn FixedOffset::local_minus_utc(self : FixedOffset) -> Int

    The signed number of seconds added to UTC to obtain local time.

    FixedOffset::not_equal

    fn FixedOffset::not_equal(x : FixedOffset, y : FixedOffset) -> Bool

    FixedOffset::offset_from_abbreviation

    fn FixedOffset::offset_from_abbreviation(_self : FixedOffset, _abbreviation : String, _near :
    NaiveDateTime
    ) -> FixedOffset?

    FixedOffset::offset_from_local

    FixedOffset::offset_from_utc

    FixedOffset::output

    fn FixedOffset::output(self : FixedOffset, logger : &Logger) -> Unit

    FixedOffset::to_string

    fn FixedOffset::to_string(self : FixedOffset) -> String

    FixedOffset::transition_bounds

    FixedOffset::utc_minus_local

    fn FixedOffset::utc_minus_local(self : FixedOffset) -> Int

    The signed number of seconds added to local time to obtain UTC: the sign-reversed local_minus_utc, positive for a western offset.

    FixedOffset::west

    fn FixedOffset::west(secs : Int) -> FixedOffset?

    The fixed offset secs seconds west of UTC (local time is behind UTC), or None if secs is outside ±86399 (±23:59:59).

    FixedOffset::zone_name

    FixedZone

    pub struct FixedZone {
    // private fields
    } derive(Eq, Hash,
    Debug
    )

    A named time zone with one constant offset (no daylight saving): the name is what zone_name (and so %Z) reports, in place of the offset text a bare FixedOffset falls back to.

    Two zones are equal only when both the name and the offset are equal.
    impl Show for FixedZone

    FixedZone::equal

    fn FixedZone::equal(FixedZone, FixedZone) -> Bool

    FixedZone::hash

    fn FixedZone::hash(self : FixedZone) -> Int

    FixedZone::hash_combine

    fn FixedZone::hash_combine(FixedZone, Hasher) -> Unit

    FixedZone::is_dst

    FixedZone::name

    fn FixedZone::name(self : FixedZone) -> String

    The name the zone was built with, e.g. "JST": the identifier of this zone, which is also what zone_name reports at every instant.

    FixedZone::new

    fn FixedZone::new(name : String, offset : FixedOffset) -> FixedZone

    A zone called name whose offset is always offset.

    FixedZone::not_equal

    fn FixedZone::not_equal(x : FixedZone, y : FixedZone) -> Bool

    FixedZone::offset

    fn FixedZone::offset(self : FixedZone) -> FixedOffset

    The zone's constant offset.

    FixedZone::offset_from_abbreviation

    fn FixedZone::offset_from_abbreviation(self : FixedZone, abbreviation : String, _near :
    NaiveDateTime
    ) -> FixedOffset?

    FixedZone::offset_from_local

    FixedZone::offset_from_utc

    FixedZone::output

    fn FixedZone::output(self : FixedZone, logger : &Logger) -> Unit

    FixedZone::to_string

    fn FixedZone::to_string(self : FixedZone) -> String

    FixedZone::transition_bounds

    FixedZone::zone_name

    Local

    pub struct Local {
    // private fields
    }

    The OS-configured local time zone, resolved from $TZ or, when unset, /etc/localtime. Only available on native: resolving it requires file I/O that js/wasm/wasm-gc have no host-provided access to.

    Local::is_dst

    Local::new

    fn Local::new() -> Local?

    The host's configured local time zone, or None if it could not be determined. Reads live OS state ($TZ, /etc/localtime), so it is not a pure function of its arguments; the $TZ precedence rules it applies are described on Local.

    Local::now

    fn Local::now() -> DateTime[Local]?

    The current instant expressed in the host's local time zone, or None if that zone could not be determined (see Local::new). The counterpart of Utc::now, and like it reads the host clock; the None is about the zone, not the clock.

    Local::offset_from_abbreviation

    fn Local::offset_from_abbreviation(self : Local, abbreviation : String, near :
    NaiveDateTime
    ) -> FixedOffset?

    Local::offset_from_local

    Local::offset_from_utc

    Local::transition_bounds

    Local::zone_name

    LocalTimeType

    pub struct LocalTimeType {
    // private fields
    } derive(Eq, Hash,
    Debug
    )

    One local time type entry from a TZif file: a UTC offset, whether it observes daylight saving, and its abbreviation (e.g. "EST", "EDT").

    LocalTimeType::abbreviation

    fn LocalTimeType::abbreviation(self : LocalTimeType) -> String

    The abbreviation for this local time type (e.g. "EST", "EDT").

    LocalTimeType::equal

    LocalTimeType::hash

    fn LocalTimeType::hash(self : LocalTimeType) -> Int

    LocalTimeType::hash_combine

    fn LocalTimeType::hash_combine(LocalTimeType, Hasher) -> Unit

    LocalTimeType::is_dst

    fn LocalTimeType::is_dst(self : LocalTimeType) -> Bool

    Whether this local time type observes daylight saving.

    LocalTimeType::new

    fn LocalTimeType::new(utc_offset : Int, is_dst : Bool, abbreviation : String) -> LocalTimeType?

    Constructs a local time type from its components, or None if utc_offset is outside ±86399 seconds (±23:59:59), the range a FixedOffset can hold; so every LocalTimeType has an offset the time-zone lookups can report.

    LocalTimeType::not_equal

    fn LocalTimeType::not_equal(x : LocalTimeType, y : LocalTimeType) -> Bool

    LocalTimeType::utc_offset

    fn LocalTimeType::utc_offset(self : LocalTimeType) -> Int

    The signed number of seconds added to UTC to obtain local time under this local time type.

    Location

    pub struct Location {
    // private fields
    } derive(Eq, Hash,
    Debug
    )

    A named IANA time zone, backed by parsed TZif (RFC 8536) data plus, when the file provides one, the POSIX TZ rule used to extrapolate offsets past the file's last recorded transition.

    Equality and hashing cover the parsed TZif data, the POSIX rule and name(), so a zone reached through an alias, or built without a name, is a different Location from the canonical one even when it resolves identically.
    impl Show for Location

    Location::equal

    fn Location::equal(Location, Location) -> Bool

    Location::from_tzif_bytes

    fn Location::from_tzif_bytes(data : Bytes) -> Location?

    Constructs a Location from raw TZif bytes, or None if parse_tzif rejects them (including a malformed POSIX TZ footer). name() reports None, since raw bytes carry no IANA identifier; use Location::from_tzif_bytes_named or Location::load to construct a Location whose name() is known.

    Location::from_tzif_bytes_named

    fn Location::from_tzif_bytes_named(name : String, data : Bytes) -> Location?

    Like Location::from_tzif_bytes, but name() reports name. Any text is accepted as given, without validation.

    Location::hash

    fn Location::hash(self : Location) -> Int

    Location::hash_combine

    fn Location::hash_combine(Location, Hasher) -> Unit

    Location::is_dst

    Location::load

    fn Location::load(name : String) -> Location?

    Loads the Location for the given embedded IANA zone name (e.g. "America/New_York"), or None if name is not a known zone or its embedded TZif bytes are malformed.

    Location::name

    fn Location::name(self : Location) -> String?

    The IANA zone identifier this Location was loaded with (e.g. "Asia/Tokyo"), or None if it was constructed via Location::from_tzif_bytes instead. Distinct from zone_name, which reports the instant-specific abbreviation (e.g. "JST"). Reports the name exactly as given to Location::load, not the canonical name an alias resolves to.

    Location::not_equal

    fn Location::not_equal(x : Location, y : Location) -> Bool

    Location::offset_from_abbreviation

    fn Location::offset_from_abbreviation(self : Location, abbreviation : String, near :
    NaiveDateTime
    ) -> FixedOffset?

    The UTC offset a zone abbreviation (e.g. "EST") denotes in this zone: the offset of the local time type in effect at near if its abbreviation matches, otherwise that of the first local time type in the zone's table with that abbreviation, or None if no type has it. The fallback is what resolves an abbreviation the zone is not observing at near, such as "EST" in summer.

    Location::offset_from_local

    Location::offset_from_utc

    Location::output

    fn Location::output(self : Location, logger : &Logger) -> Unit

    Location::to_repr

    Expands the whole transition table, so the output of a real zone is long.

    Location::to_string

    fn Location::to_string(self : Location) -> String

    Location::transition_bounds

    The validity window of the segment covering utc. See TransitionBounds.

    Location::type_at

    The local time type (offset, DST flag, and abbreviation) in effect at the given UTC instant.

    Location::utc

    fn Location::utc() -> Location

    The UTC zone as a Location, for APIs that take a Location rather than the separate Utc type: the embedded "UTC" zone, so name() is Some("UTC"). Equal to Location::load("UTC").

    Location::load("") is not an alias for UTC and returns None, so an empty name cannot silently become UTC.

    Location::zone_name

    MappedLocalTime

    pub(all) enum MappedLocalTime[T] {
    Single(T)
    Ambiguous(T, T)
    Absent
    } derive(Eq,
    Debug
    )

    The result of resolving a local (wall-clock) reading against a time zone: it can map to a single result, to two results (the "fold" at a backward DST transition, where the same wall-clock reading occurs twice), or to no result at all (the "gap" at a forward DST transition, where that wall-clock reading never occurs). T is usually a FixedOffset (see TimeZone::offset_from_local) or a DateTime[Tz] (see DateTime::from_local).

    Absent also reports components that do not form a valid reading at all (for example month 13) when a MappedLocalTime is built from components, as DateTime::from_ymd_hms and DateTime::with_* do; a caller that must tell the two apart validates the components first with NaiveDate::from_ymd and NaiveTime::from_hms.

    MappedLocalTime::earliest

    fn[T] MappedLocalTime::earliest(self : MappedLocalTime[T]) -> T?

    The earliest value self could resolve to: the sole value for Single, the first (earlier-UTC-instant) value of an Ambiguous fold, or None for Absent.

    MappedLocalTime::equal

    fn[T : Eq] MappedLocalTime::equal(MappedLocalTime[T], MappedLocalTime[T]) -> Bool

    MappedLocalTime::latest

    fn[T] MappedLocalTime::latest(self : MappedLocalTime[T]) -> T?

    The latest value self could resolve to: the sole value for Single, the second (later-UTC-instant) value of an Ambiguous fold, or None for Absent.

    MappedLocalTime::map

    fn[T, U] MappedLocalTime::map(self : MappedLocalTime[T], f : (T) -> U) -> MappedLocalTime[U]

    Applies f to every value carried by self, preserving its shape (Single/Ambiguous/Absent).

    MappedLocalTime::not_equal

    fn[T : Eq] MappedLocalTime::not_equal(x : MappedLocalTime[T], y : MappedLocalTime[T]) -> Bool

    MappedLocalTime::single

    fn[T] MappedLocalTime::single(self : MappedLocalTime[T]) -> T?

    The value, only when self is unambiguous (Single); None for Ambiguous or Absent.

    MappedLocalTime::unwrap

    fn[T] MappedLocalTime::unwrap(self : MappedLocalTime[T]) -> T

    The value of an unambiguous (Single) local time.

    Aborts, naming the reason, on Ambiguous (the reading occurs twice) or Absent (the reading never occurs); use single, earliest or latest to handle those cases instead.

    PosixTz

    pub struct PosixTz {
    // private fields
    } derive(Eq, Hash,
    Debug
    )

    A parsed POSIX TZ string (the format used in a TZif footer and the TZ environment variable), used to extrapolate offsets for instants past a TZif file's last recorded transition.

    PosixTz::equal

    fn PosixTz::equal(PosixTz, PosixTz) -> Bool

    PosixTz::hash

    fn PosixTz::hash(self : PosixTz) -> Int

    PosixTz::hash_combine

    fn PosixTz::hash_combine(PosixTz, Hasher) -> Unit

    PosixTz::is_dst

    PosixTz::not_equal

    fn PosixTz::not_equal(x : PosixTz, y : PosixTz) -> Bool

    PosixTz::offset_from_abbreviation

    fn PosixTz::offset_from_abbreviation(self : PosixTz, abbreviation : String, _near :
    NaiveDateTime
    ) -> FixedOffset?

    PosixTz::offset_from_local

    Resolves the given local (wall-clock) naive datetime to its UTC offset(s) under this POSIX TZ rule.

    PosixTz::offset_from_utc

    PosixTz::to_repr

    PosixTz::transition_bounds

    PosixTz::type_at

    The local time type (offset, DST flag, and abbreviation) in effect at the given UTC naive datetime, like Location::type_at.

    PosixTz::zone_name

    TransitionBounds

    pub struct TransitionBounds {
    // private fields
    } derive(Eq, Hash,
    Debug
    )

    The validity window of the time-zone segment covering a given instant: the local time type type_at reports is in effect from start (inclusive) until end (exclusive). None on either side means unbounded in that direction.

    TransitionBounds::end

    The instant the next segment begins, or None if this segment extends forward indefinitely (past the zone's last recorded transition, when no POSIX rule extrapolates further).

    TransitionBounds::equal

    TransitionBounds::hash

    fn TransitionBounds::hash(self : TransitionBounds) -> Int

    TransitionBounds::hash_combine

    fn TransitionBounds::hash_combine(TransitionBounds, Hasher) -> Unit

    TransitionBounds::not_equal

    fn TransitionBounds::not_equal(x : TransitionBounds, y : TransitionBounds) -> Bool

    TransitionBounds::start

    The instant this segment began, or None if it extends back indefinitely (before the zone's first recorded transition, or for a zone with no transitions at all).

    TzifData

    pub struct TzifData {
    // private fields
    } derive(Eq, Hash,
    Debug
    )

    The parsed contents of a TZif (RFC 8536) timezone-data file.

    transitions[i] (a Unix instant) switches to the local time type local_time_types[transition_types[i]]; transitions is sorted ascending. posix_tz is the POSIX TZ footer, parsed, present only in version 2 and later files, used to extrapolate offsets past the last recorded transition.

    TzifData::equal

    fn TzifData::equal(TzifData, TzifData) -> Bool

    TzifData::hash

    fn TzifData::hash(self : TzifData) -> Int

    TzifData::hash_combine

    fn TzifData::hash_combine(TzifData, Hasher) -> Unit

    TzifData::leap_seconds

    fn TzifData::leap_seconds(self : TzifData) -> Array[(Int64, Int)]

    Leap-second records (transition, correction), parsed for fidelity but not applied to civil-time arithmetic. Returns a copy.

    TzifData::local_time_types

    fn TzifData::local_time_types(self : TzifData) -> Array[LocalTimeType]

    A copy of the local time types array; changing it does not affect this value.

    TzifData::not_equal

    fn TzifData::not_equal(x : TzifData, y : TzifData) -> Bool

    TzifData::posix_tz

    fn TzifData::posix_tz(self : TzifData) -> PosixTz?

    The parsed POSIX TZ footer (e.g. "EST5EDT,M3.2.0,M11.1.0"), present only in version 2 and later files and None when the footer is empty or absent; parse_tzif has already rejected a malformed one.

    TzifData::to_repr

    TzifData::transition_types

    fn TzifData::transition_types(self : TzifData) -> Array[Int]

    A copy of the transition types array; changing it does not affect this value.

    TzifData::transitions

    fn TzifData::transitions(self : TzifData) -> Array[Int64]

    A copy of the transitions array; changing it does not affect this value.

    Utc

    pub struct Utc {
    } derive(Eq, Hash,
    Debug
    )

    The UTC time zone: a fixed offset of zero.

    Code outside this package cannot write Utc::{}; Utc::new() is the way to obtain the value.
    impl Show for Utc

    Utc::equal

    fn Utc::equal(Utc, Utc) -> Bool

    Utc::hash

    fn Utc::hash(self : Utc) -> Int

    Utc::hash_combine

    fn Utc::hash_combine(Utc, Hasher) -> Unit

    Utc::is_dst

    Utc::new

    fn Utc::new() -> Utc

    The singleton Utc value.

    Utc::not_equal

    fn Utc::not_equal(x : Utc, y : Utc) -> Bool

    Utc::now

    fn Utc::now() -> DateTime[Utc]

    The current UTC instant, read from the host's wall clock.

    The one function in this library that reads the host clock, so it is not a function of its arguments. It is total: a clock outside NaiveDate's range (about 5.8 million years either side of 1970) is a broken environment rather than a caller error, and this aborts on it. The failure Local::now reports is different, an undetermined local zone.

    Utc::offset_from_abbreviation

    fn Utc::offset_from_abbreviation(_self : Utc, _abbreviation : String, _near :
    NaiveDateTime
    ) -> FixedOffset?

    Utc::offset_from_local

    Utc::offset_from_utc

    Utc::output

    fn Utc::output(_self : Utc, logger : &Logger) -> Unit

    Utc::to_repr

    Utc::to_string

    fn Utc::to_string(self : Utc) -> String

    Utc::transition_bounds

    Utc::zone_name

    fn Utc::zone_name(_self : Utc, _dt :
    NaiveDateTime
    ) -> String

    parse_posix_tz

    fn parse_posix_tz(s : String) -> PosixTz?

    Parses a POSIX TZ string (e.g. "EST5EDT,M3.2.0,M11.1.0", "UTC0"), or None if it is malformed or names an offset beyond ±23:59:59.

    parse_tzif

    fn parse_tzif(data : Bytes) -> TzifData?

    Parses a TZif (RFC 8536) timezone-data byte buffer, or None if it is malformed or truncated, or holds a UTC offset beyond ±23:59:59. Also rejected are structures that would make lookups misbehave: no local time type, a transition naming a missing type, transitions that are not strictly increasing, an abbreviation outside the designation block, and a non-empty POSIX TZ footer that parse_posix_tz rejects.

    For a version 2/3/4 file, only the 64-bit second data block (and the POSIX TZ footer that follows it) is returned: the initial 32-bit block exists solely for backward compatibility with readers that predate 64-bit time_t.