From 9a60ffb29c95485d11e60a0c77481e41715e8485 Mon Sep 17 00:00:00 2001 From: Ruben Pollan Date: Mon, 27 Aug 2018 19:24:47 +0200 Subject: Recognize absolute times --- src/event.rs | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/event.rs b/src/event.rs index 066b691..3594a11 100644 --- a/src/event.rs +++ b/src/event.rs @@ -82,14 +82,23 @@ impl Date { } pub fn parse(date: &String, time_zone: &String) -> Result { - let tz: Tz = time_zone.parse().unwrap_or(UTC); + let absolute_time = date.chars().rev().next().unwrap() == 'Z'; + let tz: Tz = if absolute_time { + UTC + } else { + // FIXME: this should not be UTC but local timezone + time_zone.parse().unwrap_or(UTC) + }; + let date = match date.find("T") { Some(_) => { - let time = tz.datetime_from_str(&date, "%Y%m%dT%H%M%S").unwrap_or( - UTC.timestamp( - 0, - 0, - ), + let date_pattern = if absolute_time { + "%Y%m%dT%H%M%SZ" + } else { + "%Y%m%dT%H%M%S" + }; + let time = tz.datetime_from_str(&date, date_pattern).unwrap_or( + UTC.timestamp(0, 0), ); Date::Time(time) } -- cgit v1.2.3