Skip to content

Commit

Permalink
Add DateTime::Fix_offset
Browse files Browse the repository at this point in the history
  • Loading branch information
pitdicker committed May 12, 2023
1 parent 4ce9e83 commit 4d57be3
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/datetime/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,14 @@ impl<Tz: TimeZone> DateTime<Tz> {
tz.from_utc_datetime(&self.datetime)
}

/// Fix the offset from UTC to its current value, dropping the associated timezone information.
/// This it useful for converting a generic `DateTime<Tz: Timezone>` to `DateTime<FixedOffset>`.
#[inline]
#[must_use]
pub fn fix_offset(&self) -> DateTime<FixedOffset> {
self.with_timezone(&self.offset().fix())
}

/// Adds given `Duration` to the current date and time.
///
/// Returns `None` when it will result in overflow.
Expand Down

0 comments on commit 4d57be3

Please sign in to comment.