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
This commit is contained in:
Brandon W Maister 2019-09-02 14:58:54 -04:00
parent 630cade52a
commit 371cf6d29b
1 changed files with 4 additions and 2 deletions

View File

@ -202,7 +202,8 @@ impl<Tz: TimeZone> DateTime<Tz> {
#[inline] #[inline]
pub fn checked_add_signed(self, rhs: OldDuration) -> Option<DateTime<Tz>> { pub fn checked_add_signed(self, rhs: OldDuration) -> Option<DateTime<Tz>> {
let datetime = try_opt!(self.datetime.checked_add_signed(rhs)); 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. /// Subtracts given `Duration` from the current date and time.
@ -211,7 +212,8 @@ impl<Tz: TimeZone> DateTime<Tz> {
#[inline] #[inline]
pub fn checked_sub_signed(self, rhs: OldDuration) -> Option<DateTime<Tz>> { pub fn checked_sub_signed(self, rhs: OldDuration) -> Option<DateTime<Tz>> {
let datetime = try_opt!(self.datetime.checked_sub_signed(rhs)); 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. /// Subtracts another `DateTime` from the current date and time.