diff options
Diffstat (limited to 'src/model/event.rs')
-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) |