diff options
Diffstat (limited to 'src/validation')
-rw-r--r-- | src/validation/mod.rs | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src/validation/mod.rs b/src/validation/mod.rs new file mode 100644 index 0000000..07a7c4c --- /dev/null +++ b/src/validation/mod.rs @@ -0,0 +1,21 @@ +use chrono::NaiveTime; + +use crate::model::time; + +pub fn time(time: String) -> Option<Option<NaiveTime>> { + let time = time.trim(); + if time.is_empty() { + Some(None) + } else { + time::parse(time).map(Some) + } +} + +pub fn non_empty(str: String) -> Option<String> { + let str = str.trim(); + if str.is_empty() { + None + } else { + Some(str.to_string()) + } +} |