From d157525b1ce52bfa6f2cdc5713ab93b4f81b13e6 Mon Sep 17 00:00:00 2001 From: BryanLeong Date: Fri, 8 Apr 2022 16:19:17 +0800 Subject: [PATCH] Zero offset timezones should be positive (#17) --- src/parsers/fields/date.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/parsers/fields/date.rs b/src/parsers/fields/date.rs index 8187c35..498cfdd 100644 --- a/src/parsers/fields/date.rs +++ b/src/parsers/fields/date.rs @@ -16,6 +16,11 @@ use crate::{parsers::message::MessageStream, DateTime, HeaderValue}; impl DateTime { /// Returns an ISO-8601 representation of the parsed RFC5322 datetime field pub fn to_iso8601(&self) -> String { + let tz_sign = if self.tz_before_gmt && (self.tz_hour > 0 || self.tz_minute > 0) { + "-" + } else { + "+" + }; format!( "{:04}-{:02}-{:02}T{:02}:{:02}:{:02}{}{:02}:{:02}", self.year, @@ -24,7 +29,7 @@ impl DateTime { self.hour, self.minute, self.second, - if self.tz_before_gmt { "-" } else { "+" }, + tz_sign, self.tz_hour, self.tz_minute )