pub struct TimeZoneParser<'a, T: EncodingType> { /* private fields */ }Expand description
A parser for time zone offset and IANA identifier strings.
✨ Enabled with the timezone Cargo feature.
Implementations§
Source§impl<'a> TimeZoneParser<'a, Utf8>
impl<'a> TimeZoneParser<'a, Utf8>
Source§impl<'a> TimeZoneParser<'a, Utf16>
impl<'a> TimeZoneParser<'a, Utf16>
Sourcepub fn from_utf16(source: &'a [u16]) -> Self
pub fn from_utf16(source: &'a [u16]) -> Self
Creates a new TimeZoneParser from a slice of utf-16 bytes.
Source§impl<'a, T: EncodingType> TimeZoneParser<'a, T>
impl<'a, T: EncodingType> TimeZoneParser<'a, T>
Sourcepub fn new(source: &'a [T::CodeUnit]) -> Self
pub fn new(source: &'a [T::CodeUnit]) -> Self
Creates a new TimeZoneParser for the provided encoding.
Sourcepub fn parse_identifier(&mut self) -> ParserResult<TimeZoneRecord<'a, T>>
pub fn parse_identifier(&mut self) -> ParserResult<TimeZoneRecord<'a, T>>
Parse a time zone identifier that can be either an IANA identifer name or minute precision offset.
§IANA identifier example
use ixdtf::{parsers::TimeZoneParser, records::TimeZoneRecord};
let identifier = "Europe/London";
let record = TimeZoneParser::from_str(identifier)
.parse_identifier()
.unwrap();
assert_eq!(record, TimeZoneRecord::Name(identifier.as_bytes()))§Minute precision offset example
use ixdtf::{
parsers::TimeZoneParser,
records::{MinutePrecisionOffset, Sign, TimeZoneRecord},
};
let identifier = "+00:00";
let offset = match TimeZoneParser::from_str(identifier).parse_identifier() {
Ok(TimeZoneRecord::Offset(o)) => o,
_ => unreachable!(),
};
assert_eq!(offset.sign, Sign::Positive);
assert_eq!(offset.hour, 0);
assert_eq!(offset.minute, 0);§Errors
It is an error to provide a full precision offset as a time zone identifier.
NOTE: To parse either a full or minute precision,
use Self::parse_offset.
use ixdtf::{parsers::TimeZoneParser, ParseError};
let identifier = "+00:00:00";
let err = TimeZoneParser::from_str(identifier)
.parse_identifier()
.unwrap_err();
assert_eq!(err, ParseError::InvalidMinutePrecisionOffset);
let identifier = "+00:00.1";
let err = TimeZoneParser::from_str(identifier)
.parse_identifier()
.unwrap_err();
assert_eq!(err, ParseError::InvalidEnd);Sourcepub fn parse_offset(&mut self) -> ParserResult<UtcOffsetRecord>
pub fn parse_offset(&mut self) -> ParserResult<UtcOffsetRecord>
Parse a UTC offset from the provided source.
This method can parse both a minute precision and full precision offset.
§Minute precision offset example
use ixdtf::{parsers::TimeZoneParser, records::Sign};
let offset_src = "-05:00";
let parse_result =
TimeZoneParser::from_str(offset_src).parse_offset().unwrap();
assert_eq!(parse_result.sign(), Sign::Negative);
assert_eq!(parse_result.hour(), 5);
assert_eq!(parse_result.minute(), 0);
assert_eq!(parse_result.second(), None);
assert_eq!(parse_result.fraction(), None);§Full precision offset example
use ixdtf::{parsers::TimeZoneParser, records::Sign};
let offset_src = "-05:00:30.123456789";
let parse_result =
TimeZoneParser::from_str(offset_src).parse_offset().unwrap();
assert_eq!(parse_result.sign(), Sign::Negative);
assert_eq!(parse_result.hour(), 5);
assert_eq!(parse_result.minute(), 0);
assert_eq!(parse_result.second(), Some(30));
let fraction = parse_result.fraction().unwrap();
assert_eq!(fraction.to_nanoseconds(), Some(123456789));Sourcepub fn parse_iana_identifier(&mut self) -> ParserResult<&'a [T::CodeUnit]>
pub fn parse_iana_identifier(&mut self) -> ParserResult<&'a [T::CodeUnit]>
Parse an IANA identifier name.
use ixdtf::{parsers::TimeZoneParser, records::Sign};
let iana_identifier = "America/Chicago";
let parse_result = TimeZoneParser::from_str(iana_identifier)
.parse_iana_identifier()
.unwrap();
assert_eq!(parse_result, iana_identifier.as_bytes());
let iana_identifier = "Europe/Berlin";
let parse_result = TimeZoneParser::from_str(iana_identifier)
.parse_iana_identifier()
.unwrap();
assert_eq!(parse_result, iana_identifier.as_bytes());Trait Implementations§
Auto Trait Implementations§
impl<'a, T> Freeze for TimeZoneParser<'a, T>
impl<'a, T> RefUnwindSafe for TimeZoneParser<'a, T>where
<T as EncodingType>::CodeUnit: RefUnwindSafe,
impl<'a, T> Send for TimeZoneParser<'a, T>where
<T as EncodingType>::CodeUnit: Sync,
impl<'a, T> Sync for TimeZoneParser<'a, T>where
<T as EncodingType>::CodeUnit: Sync,
impl<'a, T> Unpin for TimeZoneParser<'a, T>
impl<'a, T> UnwindSafe for TimeZoneParser<'a, T>where
<T as EncodingType>::CodeUnit: RefUnwindSafe,
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
Mutably borrows from an owned value. Read more