diff options
| author | Botahamec <botahamec@outlook.com> | 2022-03-21 10:26:09 -0400 |
|---|---|---|
| committer | Botahamec <botahamec@outlook.com> | 2022-03-21 10:26:09 -0400 |
| commit | 54d431b34edcc702ac88ec7d88d42487c12b17b4 (patch) | |
| tree | 707c121a2a0626c10ac3fb4f5c0b4c253381c09b /src/datetime.rs | |
| parent | d4774180011119a00fce909e1102f45ef3a27c2c (diff) | |
Utility for converting between timezones
Diffstat (limited to 'src/datetime.rs')
| -rw-r--r-- | src/datetime.rs | 8 |
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 { |
