aboutsummaryrefslogtreecommitdiff
path: root/src/model/event.rs
diff options
context:
space:
mode:
authorJoris2024-11-17 13:00:35 +0100
committerJoris2024-11-17 13:00:35 +0100
commitfbe6787acb3c844339e34c3bf4509c36281693e6 (patch)
tree20f6d2147b18324ce2b6ba9b40e7757ec1cf9c28 /src/model/event.rs
parent0fad55124684989ec9fd9a742b5731359d0238ce (diff)
Add --start-between CLI option
Diffstat (limited to 'src/model/event.rs')
-rw-r--r--src/model/event.rs9
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)