Implement the Time struct.
This commit is contained in:
		
							parent
							
								
									a8a34e2d9c
								
							
						
					
					
						commit
						dec3242e72
					
				| @ -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; | ||||
|  | ||||
| @ -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<Self, Box<dyn std::error::Error>> { | ||||
| @ -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<Self, Box<dyn std::error::Error>> { | ||||
|         let hour = source.parse::<HourInner>()?; | ||||
|         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<Self, Box<dyn std::error::Error>> { | ||||
|         let minute = source.parse::<MinuteInner>()?; | ||||
|         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<Self, Box<dyn std::error::Error>> { | ||||
|         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 { | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Tom Alexander
						Tom Alexander