Struct TimeZoneOffsetInfo
struct TimeZoneOffsetInfo<'t> { ... }
An offset along with DST status and a time zone abbreviation.
This information can be computed from a TimeZone given a Timestamp
via TimeZone::to_offset_info.
Generally, the extra information associated with the offset is not commonly needed. And indeed, inspecting the daylight saving time status of a particular instant in a time zone usually leads to bugs. For example, not all time zone transitions are the result of daylight saving time. Some are the result of permanent changes to the standard UTC offset of a region.
This information is available via an API distinct from
TimeZone::to_offset because it is not commonly needed and because it
can sometimes be more expensive to compute.
The main use case for daylight saving time status or time zone
abbreviations is for formatting datetimes in an end user's locale. If you
want this, consider using the icu crate via jiff-icu.
The lifetime parameter 't corresponds to the lifetime of the TimeZone
that this info was extracted from.
Example
use ;
let tz = get?;
// A timestamp in DST in New York.
let ts = from_second?;
let info = tz.to_offset_info;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
// A timestamp *not* in DST in New York.
let ts = from_second?;
let info = tz.to_offset_info;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
# Ok::
Implementations
impl<'t> TimeZoneOffsetInfo<'t>
fn offset(self: &Self) -> OffsetReturns the offset.
The offset is duration, from UTC, that should be used to offset the civil time in a particular location.
Example
use ; let tz = get?; // Get the offset for 2023-03-10 00:00:00. let start = date.to_zoned?.timestamp; let info = tz.to_offset_info; assert_eq!; // Go forward a day and notice the offset changes due to DST! let start = date.to_zoned?.timestamp; let info = tz.to_offset_info; assert_eq!; # Ok::fn abbreviation(self: &Self) -> &strReturns the time zone abbreviation corresponding to this offset info.
Note that abbreviations can to be ambiguous. For example, the abbreviation
CSTcan be used for the time zonesAsia/Shanghai,America/ChicagoandAmerica/Havana.The lifetime of the string returned is tied to this
TimeZoneOffsetInfo, which may be shorter than't(the lifetime of the time zone this transition was created from).Example
use ; let tz = get?; // Get the time zone abbreviation for 2023-03-10 00:00:00. let start = date.to_zoned?.timestamp; let info = tz.to_offset_info; assert_eq!; // Go forward a day and notice the abbreviation changes due to DST! let start = date.to_zoned?.timestamp; let info = tz.to_offset_info; assert_eq!; # Ok::fn dst(self: &Self) -> DstReturns whether daylight saving time is enabled for this offset info.
Callers should generally treat this as informational only. In particular, not all time zone transitions are related to daylight saving time. For example, some transitions are a result of a region permanently changing their offset from UTC.
Example
use ; let tz = get?; // Get the DST status of 2023-03-11 00:00:00. let start = date.to_zoned?.timestamp; let info = tz.to_offset_info; assert_eq!; # Ok::
impl<'t> Clone for TimeZoneOffsetInfo<'t>
fn clone(self: &Self) -> TimeZoneOffsetInfo<'t>
impl<'t> Debug for TimeZoneOffsetInfo<'t>
fn fmt(self: &Self, f: &mut $crate::fmt::Formatter<'_>) -> $crate::fmt::Result
impl<'t> Eq for TimeZoneOffsetInfo<'t>
impl<'t> Freeze for TimeZoneOffsetInfo<'t>
impl<'t> Hash for TimeZoneOffsetInfo<'t>
fn hash<__H: $crate::hash::Hasher>(self: &Self, state: &mut __H)
impl<'t> PartialEq for TimeZoneOffsetInfo<'t>
fn eq(self: &Self, other: &TimeZoneOffsetInfo<'t>) -> bool
impl<'t> RefUnwindSafe for TimeZoneOffsetInfo<'t>
impl<'t> Send for TimeZoneOffsetInfo<'t>
impl<'t> StructuralPartialEq for TimeZoneOffsetInfo<'t>
impl<'t> Sync for TimeZoneOffsetInfo<'t>
impl<'t> Unpin for TimeZoneOffsetInfo<'t>
impl<'t> UnwindSafe for TimeZoneOffsetInfo<'t>
impl<T> Any for TimeZoneOffsetInfo<'t>
fn type_id(self: &Self) -> TypeId
impl<T> Borrow for TimeZoneOffsetInfo<'t>
fn borrow(self: &Self) -> &T
impl<T> BorrowMut for TimeZoneOffsetInfo<'t>
fn borrow_mut(self: &mut Self) -> &mut T
impl<T> CloneToUninit for TimeZoneOffsetInfo<'t>
unsafe fn clone_to_uninit(self: &Self, dest: *mut u8)
impl<T> From for TimeZoneOffsetInfo<'t>
fn from(t: T) -> TReturns the argument unchanged.
impl<T> ToOwned for TimeZoneOffsetInfo<'t>
fn to_owned(self: &Self) -> Tfn clone_into(self: &Self, target: &mut T)
impl<T, U> Into for TimeZoneOffsetInfo<'t>
fn into(self: Self) -> UCalls
U::from(self).That is, this conversion is whatever the implementation of
[From]<T> for Uchooses to do.
impl<T, U> TryFrom for TimeZoneOffsetInfo<'t>
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
impl<T, U> TryInto for TimeZoneOffsetInfo<'t>
fn try_into(self: Self) -> Result<U, <U as TryFrom<T>>::Error>