From a93bd1da475bc4b28ad9d984d340cf041ee806a2 Mon Sep 17 00:00:00 2001 From: Harald Eilertsen Date: Sat, 4 Jan 2025 15:47:57 +0100 Subject: "Fix" date/time parsing by using naive datetimes. The way timezones are stored in the VEVENTs does not lend itself very well to the way chrono parses date/time representations, so for now I just chose to ignore it by discarding the timezone info. --- src/icaltool.rs | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/icaltool.rs b/src/icaltool.rs index 9910463..2a81a68 100644 --- a/src/icaltool.rs +++ b/src/icaltool.rs @@ -14,7 +14,7 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use chrono::{DateTime, FixedOffset, Utc}; +use chrono::{NaiveDateTime, Utc}; use ical::{ IcalParser, parser::ical::component::{ @@ -66,7 +66,8 @@ impl Icaltool { } } -fn parse_datetime(datetime: Option) -> Option> { +fn parse_datetime(datetime: Option) -> Option { + dbg!(&datetime); if let Some(mut dt) = datetime { if dt.is_empty() { return None; @@ -75,7 +76,8 @@ fn parse_datetime(datetime: Option) -> Option> { if !dt.contains('T') { dt += "T000000"; } - DateTime::parse_from_str(&dt, "%Y%m%dT%H%M%S").ok() + dbg!(&dt); + dbg!(NaiveDateTime::parse_from_str(&dt, "%Y%m%dT%H%M%S").ok()) } else { None @@ -83,8 +85,8 @@ fn parse_datetime(datetime: Option) -> Option> { } fn print_event(event: &IcalEvent) { - let mut start: Option> = None; - let mut end: Option> = None; + let mut start: Option = None; + let mut end: Option = None; let mut summary = String::new(); let mut description = String::new(); @@ -99,8 +101,8 @@ fn print_event(event: &IcalEvent) { } println!("---> {} - {}: {}", - start.unwrap_or_else(|| Utc::now().fixed_offset()), - end.unwrap_or_else(|| Utc::now().fixed_offset()), + start.unwrap_or_else(|| Utc::now().naive_utc()), + end.unwrap_or_else(|| Utc::now().naive_utc()), summary); if description.len() > 0 { -- cgit v1.2.3