diff options
author | Joris | 2024-11-17 13:00:35 +0100 |
---|---|---|
committer | Joris | 2024-11-17 13:00:35 +0100 |
commit | fbe6787acb3c844339e34c3bf4509c36281693e6 (patch) | |
tree | 20f6d2147b18324ce2b6ba9b40e7757ec1cf9c28 /src/model | |
parent | 0fad55124684989ec9fd9a742b5731359d0238ce (diff) |
Add --start-between CLI option
Diffstat (limited to 'src/model')
-rw-r--r-- | src/model/event.rs | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/src/model/event.rs b/src/model/event.rs index 6cc16a2..dc052fe 100644 --- a/src/model/event.rs +++ b/src/model/event.rs @@ -1,4 +1,4 @@ -use chrono::{NaiveDate, NaiveTime}; +use chrono::{NaiveDate, NaiveTime, NaiveDateTime, Local, TimeZone}; use std::collections::HashMap; use uuid::Uuid; @@ -33,6 +33,13 @@ impl Event { }; format!("{}{}{}{}", start, end, space, self.name) } + + pub fn local_timestamp(&self) -> Option<i64> { + let time = self.start.unwrap_or(NaiveTime::from_hms_opt(0, 0, 0)?); + let naive_datetime = NaiveDateTime::new(self.date, time); + let local_datetime = Local.from_local_datetime(&naive_datetime).single()?; + Some(local_datetime.timestamp()) + } } /// Recurring events in an date range (inclusive) |