Struct TimeZoneAnnotation
pub struct TimeZoneAnnotation<'n> { /* private fields */ }
dep_jiff
and alloc
only.Expand description
An RFC 9557 time zone annotation, for use with Pieces
.
A time zone annotation is either a time zone name (typically an IANA time
zone identifier) like America/New_York
, or an offset like -05:00
. This
is normally an implementation detail of parsing into a Zoned
, but the
raw annotation can be accessed via Pieces::time_zone_annotation
after
parsing into a Pieces
.
The lifetime parameter refers to the lifetime of the time zone
name. The lifetime is static when the time zone annotation is
offset or if the name is owned. An owned value can be produced via
TimeZoneAnnotation::into_owned
when the alloc
crate feature is
enabled.
§Construction
If you’re using Pieces
, then its Pieces::with_time_zone_name
and
Pieces::with_time_zone_offset
methods should absolve you of needing to
build values of this type explicitly. But if the need arises, there are
From
impls for &str
(time zone annotation name) and Offset
(time
zone annotation offset) for this type.
§Example
use jiff::{fmt::temporal::{Pieces, TimeZoneAnnotation}, tz::offset};
// A time zone annotation from a name:
let pieces = Pieces::parse("2025-01-02T16:47-05[America/New_York]")?;
assert_eq!(
pieces.time_zone_annotation().unwrap(),
&TimeZoneAnnotation::from("America/New_York"),
);
// A time zone annotation from an offset:
let pieces = Pieces::parse("2025-01-02T16:47-05[-05:00]")?;
assert_eq!(
pieces.time_zone_annotation().unwrap(),
&TimeZoneAnnotation::from(offset(-5)),
);
Implementations§
§impl<'n> TimeZoneAnnotation<'n>
impl<'n> TimeZoneAnnotation<'n>
pub fn kind(&self) -> &TimeZoneAnnotationKind<'n>
pub fn kind(&self) -> &TimeZoneAnnotationKind<'n>
Returns the “kind” of this annotation. The kind is either a name or an offset.
§Example
use jiff::fmt::temporal::{Pieces, TimeZoneAnnotation};
// A time zone annotation from a name, which doesn't necessarily have
// to point to a valid IANA time zone.
let pieces = Pieces::parse("2025-01-02T16:47-05[Australia/Bluey]")?;
assert_eq!(
pieces.time_zone_annotation().unwrap(),
&TimeZoneAnnotation::from("Australia/Bluey"),
);
pub fn is_critical(&self) -> bool
pub fn is_critical(&self) -> bool
Returns true when this time zone is marked as “critical.” This occurs
when the time zone annotation is preceded by a !
. It is meant to
signify that, basically, implementations should error if the annotation
is invalid in some way. And when it’s absent, it’s left up to the
implementation’s discretion about what to do (including silently
ignoring the invalid annotation).
Generally speaking, Jiff ignores this altogether for time zone annotations and behaves as if it’s always true. But it’s exposed here for callers to query in case it’s useful.
§Example
use jiff::fmt::temporal::{Pieces, TimeZoneAnnotation};
// not critical
let pieces = Pieces::parse("2025-01-02T16:47-05[Australia/Bluey]")?;
assert_eq!(
Some(false),
pieces.time_zone_annotation().map(|a| a.is_critical()),
);
// critical
let pieces = Pieces::parse("2025-01-02T16:47-05[!Australia/Bluey]")?;
assert_eq!(
Some(true),
pieces.time_zone_annotation().map(|a| a.is_critical()),
);
pub fn to_time_zone(&self) -> Result<TimeZone, Error> ⓘ
pub fn to_time_zone(&self) -> Result<TimeZone, Error> ⓘ
A convenience routine for converting this annotation into a time zone.
This can fail if the annotation contains a name that couldn’t be found
in the global time zone database. If you need to use something other
than the global time zone database, then use
TimeZoneAnnotation::to_time_zone_with
.
Note that it may be more convenient to use
Pieces::to_time_zone
.
§Example
use jiff::{fmt::temporal::Pieces, tz::TimeZone};
let pieces = Pieces::parse("2025-01-02T16:47-05[Australia/Tasmania]")?;
let ann = pieces.time_zone_annotation().unwrap();
assert_eq!(
ann.to_time_zone().unwrap(),
TimeZone::get("Australia/Tasmania").unwrap(),
);
let pieces = Pieces::parse("2025-01-02T16:47-05[Australia/Bluey]")?;
let ann = pieces.time_zone_annotation().unwrap();
assert_eq!(
ann.to_time_zone().unwrap_err().to_string(),
"failed to find time zone `Australia/Bluey` in time zone database",
);
pub fn to_time_zone_with(
&self,
db: &TimeZoneDatabase,
) -> Result<TimeZone, Error> ⓘ
pub fn to_time_zone_with( &self, db: &TimeZoneDatabase, ) -> Result<TimeZone, Error> ⓘ
This is like TimeZoneAnnotation::to_time_zone
, but permits the
caller to pass in their own time zone database.
This can fail if the annotation contains a name that couldn’t be found
in the global time zone database. If you need to use something other
than the global time zone database, then use
TimeZoneAnnotation::to_time_zone_with
.
Note that it may be more convenient to use
Pieces::to_time_zone_with
.
§Example
use jiff::{fmt::temporal::Pieces, tz::TimeZone};
let pieces = Pieces::parse("2025-01-02T16:47-05[Australia/Tasmania]")?;
let ann = pieces.time_zone_annotation().unwrap();
assert_eq!(
ann.to_time_zone_with(jiff::tz::db()).unwrap(),
TimeZone::get("Australia/Tasmania").unwrap(),
);
pub fn into_owned(self) -> TimeZoneAnnotation<'static>
pub fn into_owned(self) -> TimeZoneAnnotation<'static>
Converts this time zone annotation into an “owned” value whose lifetime
is 'static
.
If this was already an “owned” value or a time zone annotation offset, then this is a no-op.
Trait Implementations§
§impl<'n> Clone for TimeZoneAnnotation<'n>
impl<'n> Clone for TimeZoneAnnotation<'n>
§fn clone(&self) -> TimeZoneAnnotation<'n>
fn clone(&self) -> TimeZoneAnnotation<'n>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more§impl<'n> Debug for TimeZoneAnnotation<'n>
impl<'n> Debug for TimeZoneAnnotation<'n>
§impl<'n> From<&'n str> for TimeZoneAnnotation<'n>
impl<'n> From<&'n str> for TimeZoneAnnotation<'n>
§fn from(string: &'n str) -> TimeZoneAnnotation<'n>
fn from(string: &'n str) -> TimeZoneAnnotation<'n>
§impl From<Offset> for TimeZoneAnnotation<'static>
impl From<Offset> for TimeZoneAnnotation<'static>
§fn from(offset: Offset) -> TimeZoneAnnotation<'static>
fn from(offset: Offset) -> TimeZoneAnnotation<'static>
§impl<'n> Hash for TimeZoneAnnotation<'n>
impl<'n> Hash for TimeZoneAnnotation<'n>
§impl<'n> PartialEq for TimeZoneAnnotation<'n>
impl<'n> PartialEq for TimeZoneAnnotation<'n>
impl<'n> Eq for TimeZoneAnnotation<'n>
impl<'n> StructuralPartialEq for TimeZoneAnnotation<'n>
Auto Trait Implementations§
impl<'n> Freeze for TimeZoneAnnotation<'n>
impl<'n> RefUnwindSafe for TimeZoneAnnotation<'n>
impl<'n> Send for TimeZoneAnnotation<'n>
impl<'n> Sync for TimeZoneAnnotation<'n>
impl<'n> Unpin for TimeZoneAnnotation<'n>
impl<'n> UnwindSafe for TimeZoneAnnotation<'n>
Blanket Implementations§
§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
§type ArchivedMetadata = ()
type ArchivedMetadata = ()
§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata,
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> ByteSized for T
impl<T> ByteSized for T
Source§const BYTE_ALIGN: usize = _
const BYTE_ALIGN: usize = _
Source§fn byte_align(&self) -> usize ⓘ
fn byte_align(&self) -> usize ⓘ
Source§fn ptr_size_ratio(&self) -> [usize; 2]
fn ptr_size_ratio(&self) -> [usize; 2]
Source§impl<T, R> Chain<R> for Twhere
T: ?Sized,
impl<T, R> Chain<R> for Twhere
T: ?Sized,
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.Source§impl<T> ExtAny for T
impl<T> ExtAny for T
Source§fn as_any_mut(&mut self) -> &mut dyn Anywhere
Self: Sized,
fn as_any_mut(&mut self) -> &mut dyn Anywhere
Self: Sized,
Source§impl<T> ExtMem for Twhere
T: ?Sized,
impl<T> ExtMem for Twhere
T: ?Sized,
Source§const NEEDS_DROP: bool = _
const NEEDS_DROP: bool = _
Source§fn mem_align_of_val(&self) -> usize ⓘ
fn mem_align_of_val(&self) -> usize ⓘ
Source§fn mem_size_of_val(&self) -> usize ⓘ
fn mem_size_of_val(&self) -> usize ⓘ
Source§fn mem_needs_drop(&self) -> bool
fn mem_needs_drop(&self) -> bool
true
if dropping values of this type matters. Read moreSource§fn mem_forget(self)where
Self: Sized,
fn mem_forget(self)where
Self: Sized,
self
without running its destructor. Read moreSource§fn mem_replace(&mut self, other: Self) -> Selfwhere
Self: Sized,
fn mem_replace(&mut self, other: Self) -> Selfwhere
Self: Sized,
Source§unsafe fn mem_zeroed<T>() -> T
unsafe fn mem_zeroed<T>() -> T
unsafe_layout
only.T
represented by the all-zero byte-pattern. Read moreSource§unsafe fn mem_transmute_copy<Src, Dst>(src: &Src) -> Dst
unsafe fn mem_transmute_copy<Src, Dst>(src: &Src) -> Dst
unsafe_layout
only.T
represented by the all-zero byte-pattern. Read moreSource§fn mem_as_bytes(&self) -> &[u8] ⓘ
fn mem_as_bytes(&self) -> &[u8] ⓘ
unsafe_slice
only.§impl<S> FromSample<S> for S
impl<S> FromSample<S> for S
fn from_sample_(s: S) -> S
Source§impl<T> Hook for T
impl<T> Hook for T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more§impl<F, T> IntoSample<T> for Fwhere
T: FromSample<F>,
impl<F, T> IntoSample<T> for Fwhere
T: FromSample<F>,
fn into_sample(self) -> T
§impl<T> LayoutRaw for T
impl<T> LayoutRaw for T
§fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError> ⓘ
fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError> ⓘ
§impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
§unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
§fn resolve_niched(out: Place<NichedOption<T, N1>>)
fn resolve_niched(out: Place<NichedOption<T, N1>>)
out
indicating that a T
is niched.