Struct TimeZoneParser

Source
pub struct TimeZoneParser<'a> { /* 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>

Source

pub fn from_utf8(source: &'a [u8]) -> Self

Creates a new TimeZoneParser from a slice of utf-8 bytes.

Source

pub fn from_str(source: &'a str) -> Self

Creates a new TimeZoneParser from a source &str.

Source

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::{records::Sign, TimeZoneParser};

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::{records::Sign, TimeZoneParser};

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));
Source

pub fn parse_iana_identifier(&mut self) -> ParserResult<&'a [u8]>

Parse an IANA identifier name.

use ixdtf::parsers::{records::Sign, TimeZoneParser};

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§

Source§

impl<'a> Debug for TimeZoneParser<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for TimeZoneParser<'a>

§

impl<'a> RefUnwindSafe for TimeZoneParser<'a>

§

impl<'a> Send for TimeZoneParser<'a>

§

impl<'a> Sync for TimeZoneParser<'a>

§

impl<'a> Unpin for TimeZoneParser<'a>

§

impl<'a> UnwindSafe for TimeZoneParser<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.