diff --git a/src/datatype.rs b/src/datatype.rs index 9336c448..fd1ba7ba 100644 --- a/src/datatype.rs +++ b/src/datatype.rs @@ -59,6 +59,26 @@ impl DataTypeTrait for DataType { matches!(*self, DataType::String(_)) } + #[cfg(feature = "dates")] + fn is_duration(&self) -> bool { + matches!(*self, DataType::Duration(_)) + } + + #[cfg(feature = "dates")] + fn is_duration_iso(&self) -> bool { + matches!(*self, DataType::DurationIso(_)) + } + + #[cfg(feature = "dates")] + fn is_datetime(&self) -> bool { + matches!(*self, DataType::DateTime(_)) + } + + #[cfg(feature = "dates")] + fn is_datetime_iso(&self) -> bool { + matches!(*self, DataType::DateTimeIso(_)) + } + fn get_int(&self) -> Option { if let DataType::Int(v) = self { Some(*v) @@ -398,6 +418,26 @@ impl DataTypeTrait for DataTypeRef<'_> { matches!(*self, DataTypeRef::String(_) | DataTypeRef::SharedString(_)) } + #[cfg(feature = "dates")] + fn is_duration(&self) -> bool { + matches!(*self, DataTypeRef::Duration(_)) + } + + #[cfg(feature = "dates")] + fn is_duration_iso(&self) -> bool { + matches!(*self, DataTypeRef::DurationIso(_)) + } + + #[cfg(feature = "dates")] + fn is_datetime(&self) -> bool { + matches!(*self, DataTypeRef::DateTime(_)) + } + + #[cfg(feature = "dates")] + fn is_datetime_iso(&self) -> bool { + matches!(*self, DataTypeRef::DateTimeIso(_)) + } + fn get_int(&self) -> Option { if let DataTypeRef::Int(v) = self { Some(*v) @@ -553,6 +593,22 @@ pub trait DataTypeTrait { /// Assess if datatype is a string fn is_string(&self) -> bool; + /// Assess if datatype is a duration + #[cfg(feature = "dates")] + fn is_duration(&self) -> bool; + + /// Assess if datatype is an ISO8601 duration + #[cfg(feature = "dates")] + fn is_duration_iso(&self) -> bool; + + /// Assess if datatype is a datetime + #[cfg(feature = "dates")] + fn is_datetime(&self) -> bool; + + /// Assess if datatype is an ISO8601 datetime + #[cfg(feature = "dates")] + fn is_datetime_iso(&self) -> bool; + /// Try getting int value fn get_int(&self) -> Option; diff --git a/tests/test.rs b/tests/test.rs index 5f317f23..446098e0 100644 --- a/tests/test.rs +++ b/tests/test.rs @@ -2,7 +2,8 @@ use calamine::DataType::{ Bool, DateTime, DateTimeIso, Duration, DurationIso, Empty, Error, Float, String, }; use calamine::{ - open_workbook, open_workbook_auto, Ods, Reader, Sheet, SheetType, SheetVisible, Xls, Xlsb, Xlsx, + open_workbook, open_workbook_auto, DataTypeTrait, Ods, Reader, Sheet, SheetType, SheetVisible, + Xls, Xlsb, Xlsx, }; use calamine::{CellErrorType::*, DataType}; use std::io::Cursor;