From 54d431b34edcc702ac88ec7d88d42487c12b17b4 Mon Sep 17 00:00:00 2001 From: Botahamec Date: Mon, 21 Mar 2022 10:26:09 -0400 Subject: Utility for converting between timezones --- src/datetime.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/datetime.rs b/src/datetime.rs index a46d0b7..9332de1 100644 --- a/src/datetime.rs +++ b/src/datetime.rs @@ -48,12 +48,16 @@ impl DateTime { .add_seconds_overflowing(self.offset().seconds_ahead().into()) } + pub fn into_timezone(&self, timezone: NewZone) -> DateTime { + DateTime::::from_utc(self.utc_datetime, timezone) + } + pub fn as_utc(&self) -> DateTime { - DateTime::::from_utc(self.utc_datetime, Utc) + self.into_timezone(Utc) } pub fn as_tai(&self) -> DateTime { - DateTime::::from_utc(self.utc_datetime, Tai) + self.into_timezone(Tai) } pub fn unix_timestamp(&self) -> UnixTimestamp { -- cgit v1.2.3