diff --git a/src/types/mod.rs b/src/types/mod.rs index 13fc8db..8c7bd4b 100644 --- a/src/types/mod.rs +++ b/src/types/mod.rs @@ -60,11 +60,15 @@ pub use object::DayOfMonthInner; pub use object::Entity; pub use object::ExportSnippet; pub use object::FootnoteReference; +pub use object::Hour; +pub use object::HourInner; pub use object::InlineBabelCall; pub use object::InlineSourceBlock; pub use object::Italic; pub use object::LatexFragment; pub use object::LineBreak; +pub use object::Minute; +pub use object::MinuteInner; pub use object::Month; pub use object::MonthInner; pub use object::Object; @@ -79,6 +83,7 @@ pub use object::StrikeThrough; pub use object::Subscript; pub use object::Superscript; pub use object::Target; +pub use object::Time; pub use object::Timestamp; pub use object::TimestampRangeType; pub use object::TimestampType; diff --git a/src/types/object.rs b/src/types/object.rs index dcc72bc..885745a 100644 --- a/src/types/object.rs +++ b/src/types/object.rs @@ -209,6 +209,8 @@ pub enum TimestampRangeType { pub type YearInner = u16; pub type MonthInner = u8; pub type DayOfMonthInner = u8; +pub type HourInner = u8; +pub type MinuteInner = u8; #[derive(Debug, PartialEq, Clone)] pub struct Year(YearInner); @@ -219,6 +221,12 @@ pub struct Month(MonthInner); #[derive(Debug, PartialEq, Clone)] pub struct DayOfMonth(DayOfMonthInner); +#[derive(Debug, PartialEq, Clone)] +pub struct Hour(HourInner); + +#[derive(Debug, PartialEq, Clone)] +pub struct Minute(MinuteInner); + impl Year { // TODO: Make a real error type instead of a boxed any error. pub fn new<'s>(source: &'s str) -> Result> { @@ -261,6 +269,36 @@ impl DayOfMonth { } } +impl Hour { + // TODO: Make a real error type instead of a boxed any error. + pub fn new<'s>(source: &'s str) -> Result> { + let hour = source.parse::()?; + if hour < 1 || hour > 23 { + Err("Hour exceeds possible range.")?; + } + Ok(Hour(hour)) + } + + pub fn get_value(&self) -> HourInner { + self.0 + } +} + +impl Minute { + // TODO: Make a real error type instead of a boxed any error. + pub fn new<'s>(source: &'s str) -> Result> { + let minute = source.parse::()?; + if minute < 1 || minute > 59 { + Err("Minute exceeds possible range.")?; + } + Ok(Minute(minute)) + } + + pub fn get_value(&self) -> MinuteInner { + self.0 + } +} + #[derive(Debug, PartialEq, Clone)] pub struct Date<'s> { year: Year, @@ -319,6 +357,40 @@ impl<'s> Date<'s> { } } +#[derive(Debug, PartialEq, Clone)] +pub struct Time<'s> { + hour: Hour, + minute: Minute, + postfix: Option<&'s str>, +} + +impl<'s> Time<'s> { + // TODO: Make a real error type instead of a boxed any error. + pub fn new( + hour: Hour, + minute: Minute, + postfix: Option<&'s str>, + ) -> Result> { + Ok(Time { + hour, + minute, + postfix, + }) + } + + pub fn get_hour(&self) -> &Hour { + &self.hour + } + + pub fn get_minute(&self) -> &Minute { + &self.minute + } + + pub fn get_postfix(&self) -> Option<&'s str> { + self.postfix + } +} + impl<'s> GetStandardProperties<'s> for Object<'s> { fn get_standard_properties<'b>(&'b self) -> &'b dyn StandardProperties<'s> { match self {