From 371cf6d29bdc74c847870b22ab390e5dfa7888f4 Mon Sep 17 00:00:00 2001 From: Brandon W Maister Date: Mon, 2 Sep 2019 14:58:54 -0400 Subject: [PATCH] Adjust timezones after doing Duration addition The internal, tz-independent timestamp was valid, but since the timezone offset could change as you add or subtract a second or two you would get nonsense/nonexistent times when you observed them. Fixes #318 --- src/datetime.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/datetime.rs b/src/datetime.rs index e6a0657..b4881bf 100644 --- a/src/datetime.rs +++ b/src/datetime.rs @@ -202,7 +202,8 @@ impl DateTime { #[inline] pub fn checked_add_signed(self, rhs: OldDuration) -> Option> { let datetime = try_opt!(self.datetime.checked_add_signed(rhs)); - Some(DateTime { datetime: datetime, offset: self.offset }) + let tz = self.timezone(); + Some(tz.from_utc_datetime(&datetime)) } /// Subtracts given `Duration` from the current date and time. @@ -211,7 +212,8 @@ impl DateTime { #[inline] pub fn checked_sub_signed(self, rhs: OldDuration) -> Option> { let datetime = try_opt!(self.datetime.checked_sub_signed(rhs)); - Some(DateTime { datetime: datetime, offset: self.offset }) + let tz = self.timezone(); + Some(tz.from_utc_datetime(&datetime)) } /// Subtracts another `DateTime` from the current date and time.