MappedLocalTime

Type Alias MappedLocalTime 

Source
pub type MappedLocalTime<T> = LocalResult<T>;
Expand description

The result of mapping a local time to a concrete instant in a given time zone.

The calculation to go from a local time (wall clock time) to an instant in UTC can end up in three cases:

  • A single, simple result.
  • An ambiguous result when the clock is turned backwards during a transition due to for example DST.
  • No result when the clock is turned forwards during a transition due to for example DST.

In wasm, when using Local, only the LocalResult::Single variant is returned. Specifically:

  • When the clock is turned backwards, where Ambiguous(earliest, latest) would be expected, Single(earliest) is returned instead.
  • When the clock is turned forwards, where None would be expected, Single(t) is returned, with t being the requested local time represented as though there is no transition on that day (i.e. still “summer time”)

This is caused because of limitations in the JavaScript Date API, which always parses a local time as a single, valid time - even for an input which describes a nonexistent or ambiguous time.

See further discussion and workarounds in https://github.com/chronotope/chrono/issues/1701.

When the clock is turned backwards it creates a fold in local time, during which the local time is ambiguous. When the clock is turned forwards it creates a gap in local time, during which the local time is missing, or does not exist.

Chrono does not return a default choice or invalid data during time zone transitions, but has the MappedLocalTime type to help deal with the result correctly.

The type of T is usually a DateTime but may also be only an offset.

Aliased Type§

pub enum MappedLocalTime<T> {
    Single(T),
    Ambiguous(T, T),
    None,
}

Variants§

§

Single(T)

The local time maps to a single unique result.

§

Ambiguous(T, T)

The local time is ambiguous because there is a fold in the local time.

This variant contains the two possible results, in the order (earliest, latest).

§

None

The local time does not exist because there is a gap in the local time.

This variant may also be returned if there was an error while resolving the local time, caused by for example missing time zone data files, an error in an OS API, or overflow.