Struct ixdtf::parsers::IxdtfParser
source · pub struct IxdtfParser<'a> { /* private fields */ }
Expand description
IxdtfParser
is the primary parser implementation of ixdtf
.
This parser provides various options for parsing date/time strings with the extended notation
laid out in RFC9557 along with other variations laid out in the Temporal
.
use ixdtf::parsers::{
records::{Sign, TimeZoneRecord, UtcOffsetRecord},
IxdtfParser,
};
let ixdtf_str = "2024-03-02T08:48:00-05:00[America/New_York]";
let result = IxdtfParser::from_str(ixdtf_str).parse().unwrap();
let date = result.date.unwrap();
let time = result.time.unwrap();
let offset = result.offset.unwrap().resolve_rfc_9557();
let tz_annotation = result.tz.unwrap();
assert_eq!(date.year, 2024);
assert_eq!(date.month, 3);
assert_eq!(date.day, 2);
assert_eq!(time.hour, 8);
assert_eq!(time.minute, 48);
assert_eq!(offset.sign, Sign::Negative);
assert_eq!(offset.hour, 5);
assert_eq!(offset.minute, 0);
assert!(!tz_annotation.critical);
assert_eq!(tz_annotation.tz, TimeZoneRecord::Name("America/New_York".as_bytes()));
Implementations§
source§impl<'a> IxdtfParser<'a>
impl<'a> IxdtfParser<'a>
sourcepub fn from_utf8(source: &'a [u8]) -> Self
pub fn from_utf8(source: &'a [u8]) -> Self
Creates a new IxdtfParser
from a slice of utf-8 bytes.
sourcepub fn parse(&mut self) -> ParserResult<IxdtfParseRecord<'a>>
pub fn parse(&mut self) -> ParserResult<IxdtfParseRecord<'a>>
Parses the source as an extended Date/Time string.
This is the baseline parse method for ixdtf
. For this method, the
TimeRecord, UTCOffsetRecord, and all annotations are optional.
§Example
sourcepub fn parse_with_annotation_handler(
&mut self,
handler: impl FnMut(Annotation<'a>) -> Option<Annotation<'a>>,
) -> ParserResult<IxdtfParseRecord<'a>>
pub fn parse_with_annotation_handler( &mut self, handler: impl FnMut(Annotation<'a>) -> Option<Annotation<'a>>, ) -> ParserResult<IxdtfParseRecord<'a>>
Parses the source as an extended Date/Time string with an Annotation handler.
For more, see Implementing Annotation Handlers
sourcepub fn parse_year_month(&mut self) -> ParserResult<IxdtfParseRecord<'a>>
pub fn parse_year_month(&mut self) -> ParserResult<IxdtfParseRecord<'a>>
Parses the source as an extended YearMonth string.
§Example
let extended_year_month = "2020-11[u-ca=iso8601]";
let result = IxdtfParser::from_str(extended_year_month)
.parse_year_month()
.unwrap();
let date = result.date.unwrap();
assert_eq!(date.year, 2020);
assert_eq!(date.month, 11);
sourcepub fn parse_year_month_with_annotation_handler(
&mut self,
handler: impl FnMut(Annotation<'a>) -> Option<Annotation<'a>>,
) -> ParserResult<IxdtfParseRecord<'a>>
pub fn parse_year_month_with_annotation_handler( &mut self, handler: impl FnMut(Annotation<'a>) -> Option<Annotation<'a>>, ) -> ParserResult<IxdtfParseRecord<'a>>
Parses the source as an extended YearMonth string with an Annotation handler.
For more, see Implementing Annotation Handlers
sourcepub fn parse_month_day(&mut self) -> ParserResult<IxdtfParseRecord<'a>>
pub fn parse_month_day(&mut self) -> ParserResult<IxdtfParseRecord<'a>>
Parses the source as an extended MonthDay string.
§Example
let extended_month_day = "1107[+04:00]";
let result = IxdtfParser::from_str(extended_month_day)
.parse_month_day()
.unwrap();
let date = result.date.unwrap();
assert_eq!(date.month, 11);
assert_eq!(date.day, 7);
sourcepub fn parse_month_day_with_annotation_handler(
&mut self,
handler: impl FnMut(Annotation<'a>) -> Option<Annotation<'a>>,
) -> ParserResult<IxdtfParseRecord<'a>>
pub fn parse_month_day_with_annotation_handler( &mut self, handler: impl FnMut(Annotation<'a>) -> Option<Annotation<'a>>, ) -> ParserResult<IxdtfParseRecord<'a>>
Parses the source as an extended MonthDay string with an Annotation handler.
For more, see Implementing Annotation Handlers
sourcepub fn parse_time(&mut self) -> ParserResult<IxdtfParseRecord<'a>>
pub fn parse_time(&mut self) -> ParserResult<IxdtfParseRecord<'a>>
Parses the source as an extended Time string.
§Example
let extended_time = "12:01:04-05:00[America/New_York][u-ca=iso8601]";
let result = IxdtfParser::from_str(extended_time).parse_time().unwrap();
let time = result.time.unwrap();
let offset = result.offset.unwrap().resolve_rfc_9557();
let tz_annotation = result.tz.unwrap();
assert_eq!(time.hour, 12);
assert_eq!(time.minute, 1);
assert_eq!(time.second, 4);
assert_eq!(offset.sign, Sign::Negative);
assert_eq!(offset.hour, 5);
assert_eq!(offset.minute, 0);
assert!(!tz_annotation.critical);
assert_eq!(tz_annotation.tz, TimeZoneRecord::Name("America/New_York".as_bytes()));
sourcepub fn parse_time_with_annotation_handler(
&mut self,
handler: impl FnMut(Annotation<'a>) -> Option<Annotation<'a>>,
) -> ParserResult<IxdtfParseRecord<'a>>
pub fn parse_time_with_annotation_handler( &mut self, handler: impl FnMut(Annotation<'a>) -> Option<Annotation<'a>>, ) -> ParserResult<IxdtfParseRecord<'a>>
Parses the source as an extended Time string with an Annotation handler.
For more, see Implementing Annotation Handlers