From 79db3f6b4ff56dd3e3edb18b3c8e144e10d2b39c Mon Sep 17 00:00:00 2001 From: FliegendeWurst <2012gdwu+github@posteo.de> Date: Fri, 7 May 2021 11:56:54 +0200 Subject: [PATCH] Fix timezone handling of ical DT --- src/ical_parsing.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/ical_parsing.rs b/src/ical_parsing.rs index 606740b..c8ec571 100644 --- a/src/ical_parsing.rs +++ b/src/ical_parsing.rs @@ -1,4 +1,4 @@ -use chrono::{Duration, NaiveDate, NaiveDateTime}; +use chrono::{Duration, Local, NaiveDate, NaiveDateTime, TimeZone}; use once_cell::sync::Lazy; use regex::Regex; use ical::parser::ical::component::IcalEvent; @@ -94,6 +94,7 @@ fn process_event(event: IcalEvent) -> Result { }) } +/// returns local time fn process_dt(value: &str) -> Result { // 20200626T140000 if value.len() != 15 && value.len() != 16 { // allow Z suffix @@ -106,8 +107,13 @@ fn process_dt(value: &str) -> Result { let hour = value[9..11].parse()?; let minute = value[11..13].parse()?; let second = value[13..15].parse()?; + let mut date = NaiveDate::from_ymd(year, month, day).and_hms(hour, minute, second); + if value.ends_with('Z') { + // get local time + date = TimeZone::from_utc_datetime(&Local, &date).naive_local() + } - Ok(NaiveDate::from_ymd(year, month, day).and_hms(hour, minute, second)) + Ok(date) } pub static DURATION_PATTERN: Lazy = Lazy::new(|| {