pub struct IanaParser {
data: DataPayload<TimezoneIdentifiersIanaCoreV1>,
checksum: u64,
}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_WayneAmerica/Indiana/IndianapolisAmerica/IndianapolisUS/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);Fields§
§data: DataPayload<TimezoneIdentifiersIanaCoreV1>§checksum: u64Implementations§
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_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 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more