pub struct IanaParser { /* private fields */ }
Expand description
A parser for parsing an IANA time zone ID to a TimeZone
type.
There are approximately 600 IANA identifiers and 450 TimeZone
identifiers.
These lists grow very slowly; in a typical year, 2-3 new identifiers are added.
This means that multiple IANA identifiers map to the same TimeZone
. For example, the
following four IANA identifiers all map to the same TimeZone
:
America/Fort_Wayne
America/Indiana/Indianapolis
America/Indianapolis
US/East-Indiana
For each TimeZone
, there is one “canonical” IANA time zone ID (for the above example, it is
America/Indiana/Indianapolis
). Note that the canonical identifier can change over time.
For example, the identifier Europe/Kiev
was renamed to the newly-added identifier Europe/Kyiv
in 2022.
§Examples
use icu::locale::subtags::subtag;
use icu::time::zone::IanaParser;
use icu::time::TimeZone;
let parser = IanaParser::new();
// The IANA zone "Australia/Melbourne" is the BCP-47 zone "aumel":
assert_eq!(
parser.parse("Australia/Melbourne"),
TimeZone(subtag!("aumel"))
);
// Parsing is ASCII-case-insensitive:
assert_eq!(
parser.parse("australia/melbourne"),
TimeZone(subtag!("aumel"))
);
// The IANA zone "Australia/Victoria" is an alias:
assert_eq!(
parser.parse("Australia/Victoria"),
TimeZone(subtag!("aumel"))
);
// The IANA zone "Australia/Boing_Boing" does not exist
// (maybe not *yet*), so it produces the special unknown
// time zone in order for this operation to be infallible:
assert_eq!(parser.parse("Australia/Boing_Boing"), TimeZone::UNKNOWN);
Implementations§
Source§impl IanaParser
impl IanaParser
Sourcepub fn new() -> IanaParserBorrowed<'static>
pub fn new() -> IanaParserBorrowed<'static>
Creates a new IanaParser
using compiled data.
See IanaParser
for an example.
✨ Enabled with the compiled_data
Cargo feature.
Sourcepub fn try_new_with_buffer_provider(
provider: &(impl BufferProvider + ?Sized),
) -> Result<Self, DataError>
pub fn try_new_with_buffer_provider( provider: &(impl BufferProvider + ?Sized), ) -> Result<Self, DataError>
A version of [Self :: new
] that uses custom data provided by a BufferProvider
.
✨ Enabled with the serde
feature.
Sourcepub fn try_new_unstable<P>(provider: &P) -> Result<Self, DataError>
pub fn try_new_unstable<P>(provider: &P) -> Result<Self, DataError>
A version of Self::new
that uses custom data provided by a DataProvider
.
Sourcepub fn as_borrowed(&self) -> IanaParserBorrowed<'_>
pub fn as_borrowed(&self) -> IanaParserBorrowed<'_>
Returns a borrowed version of the parser that can be queried.
This avoids a small potential indirection cost when querying the parser.
Trait Implementations§
Source§impl AsRef<IanaParser> for IanaParser
impl AsRef<IanaParser> for IanaParser
Source§fn as_ref(&self) -> &IanaParser
fn as_ref(&self) -> &IanaParser
Source§impl Clone for IanaParser
impl Clone for IanaParser
Source§fn clone(&self) -> IanaParser
fn clone(&self) -> IanaParser
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreAuto Trait Implementations§
impl Freeze for IanaParser
impl RefUnwindSafe for IanaParser
impl !Send for IanaParser
impl !Sync for IanaParser
impl Unpin for IanaParser
impl UnwindSafe for IanaParser
Blanket Implementations§
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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