Type Alias MappedLocalTime
pub type MappedLocalTime<T> = LocalResult<T>;
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
Nonewould be expected,Single(t)is returned, withtbeing 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.