From fbe6787acb3c844339e34c3bf4509c36281693e6 Mon Sep 17 00:00:00 2001 From: Joris Date: Sun, 17 Nov 2024 13:00:35 +0100 Subject: Add --start-between CLI option --- src/model/event.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'src/model') 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 { + 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) -- cgit v1.2.3