Type Alias chrono::offset::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.
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§
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.
Implementations§
source§impl<T> MappedLocalTime<T>
impl<T> MappedLocalTime<T>
sourcepub fn single(self) -> Option<T>
pub fn single(self) -> Option<T>
Returns Some
if the time zone mapping has a single result.
§Errors
Returns None
if local time falls in a fold or gap in the local time, or if there was
an error.
sourcepub fn earliest(self) -> Option<T>
pub fn earliest(self) -> Option<T>
Returns the earliest possible result of a the time zone mapping.
§Errors
Returns None
if local time falls in a gap in the local time, or if there was an error.
sourcepub fn latest(self) -> Option<T>
pub fn latest(self) -> Option<T>
Returns the latest possible result of a the time zone mapping.
§Errors
Returns None
if local time falls in a gap in the local time, or if there was an error.
sourcepub fn map<U, F: FnMut(T) -> U>(self, f: F) -> MappedLocalTime<U>
pub fn map<U, F: FnMut(T) -> U>(self, f: F) -> MappedLocalTime<U>
Maps a MappedLocalTime<T>
into MappedLocalTime<U>
with given function.
source§impl<Tz: TimeZone> MappedLocalTime<Date<Tz>>
impl<Tz: TimeZone> MappedLocalTime<Date<Tz>>
sourcepub fn and_time(self, time: NaiveTime) -> MappedLocalTime<DateTime<Tz>>
pub fn and_time(self, time: NaiveTime) -> MappedLocalTime<DateTime<Tz>>
Makes a new DateTime
from the current date and given NaiveTime
.
The offset in the current date is preserved.
Propagates any error. Ambiguous result would be discarded.
sourcepub fn and_hms_opt(
self,
hour: u32,
min: u32,
sec: u32,
) -> MappedLocalTime<DateTime<Tz>>
pub fn and_hms_opt( self, hour: u32, min: u32, sec: u32, ) -> MappedLocalTime<DateTime<Tz>>
Makes a new DateTime
from the current date, hour, minute and second.
The offset in the current date is preserved.
Propagates any error. Ambiguous result would be discarded.
sourcepub fn and_hms_milli_opt(
self,
hour: u32,
min: u32,
sec: u32,
milli: u32,
) -> MappedLocalTime<DateTime<Tz>>
pub fn and_hms_milli_opt( self, hour: u32, min: u32, sec: u32, milli: u32, ) -> MappedLocalTime<DateTime<Tz>>
Makes a new DateTime
from the current date, hour, minute, second and millisecond.
The millisecond part can exceed 1,000 in order to represent the leap second.
The offset in the current date is preserved.
Propagates any error. Ambiguous result would be discarded.
sourcepub fn and_hms_micro_opt(
self,
hour: u32,
min: u32,
sec: u32,
micro: u32,
) -> MappedLocalTime<DateTime<Tz>>
pub fn and_hms_micro_opt( self, hour: u32, min: u32, sec: u32, micro: u32, ) -> MappedLocalTime<DateTime<Tz>>
Makes a new DateTime
from the current date, hour, minute, second and microsecond.
The microsecond part can exceed 1,000,000 in order to represent the leap second.
The offset in the current date is preserved.
Propagates any error. Ambiguous result would be discarded.
sourcepub fn and_hms_nano_opt(
self,
hour: u32,
min: u32,
sec: u32,
nano: u32,
) -> MappedLocalTime<DateTime<Tz>>
pub fn and_hms_nano_opt( self, hour: u32, min: u32, sec: u32, nano: u32, ) -> MappedLocalTime<DateTime<Tz>>
Makes a new DateTime
from the current date, hour, minute, second and nanosecond.
The nanosecond part can exceed 1,000,000,000 in order to represent the leap second.
The offset in the current date is preserved.
Propagates any error. Ambiguous result would be discarded.
source§impl<T: Debug> MappedLocalTime<T>
impl<T: Debug> MappedLocalTime<T>
sourcepub fn unwrap(self) -> T
pub fn unwrap(self) -> T
Returns a single unique conversion result or panics.
unwrap()
is best combined with time zone types where the mapping can never fail like
Utc
and FixedOffset
. Note that for FixedOffset
there is a rare case where a
resulting DateTime
can be out of range.
§Panics
Panics if the local time falls within a fold or a gap in the local time, and on any
error that may have been returned by the type implementing TimeZone
.