summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBotahamec <botahamec@outlook.com>2022-03-21 10:26:09 -0400
committerBotahamec <botahamec@outlook.com>2022-03-21 10:26:09 -0400
commit54d431b34edcc702ac88ec7d88d42487c12b17b4 (patch)
tree707c121a2a0626c10ac3fb4f5c0b4c253381c09b
parentd4774180011119a00fce909e1102f45ef3a27c2c (diff)
Utility for converting between timezones
-rw-r--r--src/datetime.rs8
1 files changed, 6 insertions, 2 deletions
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<Tz: TimeZone> DateTime<Tz> {
.add_seconds_overflowing(self.offset().seconds_ahead().into())
}
+ pub fn into_timezone<NewZone: TimeZone>(&self, timezone: NewZone) -> DateTime<NewZone> {
+ DateTime::<NewZone>::from_utc(self.utc_datetime, timezone)
+ }
+
pub fn as_utc(&self) -> DateTime<Utc> {
- DateTime::<Utc>::from_utc(self.utc_datetime, Utc)
+ self.into_timezone(Utc)
}
pub fn as_tai(&self) -> DateTime<Tai> {
- DateTime::<Tai>::from_utc(self.utc_datetime, Tai)
+ self.into_timezone(Tai)
}
pub fn unix_timestamp(&self) -> UnixTimestamp {