diff options
author | Harald Eilertsen <haraldei@anduin.net> | 2025-01-04 15:47:57 +0100 |
---|---|---|
committer | Harald Eilertsen <haraldei@anduin.net> | 2025-01-04 15:47:57 +0100 |
commit | a93bd1da475bc4b28ad9d984d340cf041ee806a2 (patch) | |
tree | c93825b3ddd6beaedee7ae37d4ee4680cc618382 | |
parent | 4fd3607bb9c0c1fa9c476860d44424c89150b2f6 (diff) | |
download | icaltool-a93bd1da475bc4b28ad9d984d340cf041ee806a2.tar.gz icaltool-a93bd1da475bc4b28ad9d984d340cf041ee806a2.tar.bz2 icaltool-a93bd1da475bc4b28ad9d984d340cf041ee806a2.zip |
"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.
-rw-r--r-- | src/icaltool.rs | 16 |
1 files changed, 9 insertions, 7 deletions
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 <https://www.gnu.org/licenses/>. -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<String>) -> Option<DateTime<FixedOffset>> { +fn parse_datetime(datetime: Option<String>) -> Option<NaiveDateTime> { + dbg!(&datetime); if let Some(mut dt) = datetime { if dt.is_empty() { return None; @@ -75,7 +76,8 @@ fn parse_datetime(datetime: Option<String>) -> Option<DateTime<FixedOffset>> { 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<String>) -> Option<DateTime<FixedOffset>> { } fn print_event(event: &IcalEvent) { - let mut start: Option<DateTime<FixedOffset>> = None; - let mut end: Option<DateTime<FixedOffset>> = None; + let mut start: Option<NaiveDateTime> = None; + let mut end: Option<NaiveDateTime> = 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 { |