summaryrefslogtreecommitdiffstats
path: root/vendor/time/src/offset_date_time.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-30 03:57:19 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-30 03:57:19 +0000
commita0b8f38ab54ac451646aa00cd5e91b6c76f22a84 (patch)
treefc451898ccaf445814e26b46664d78702178101d /vendor/time/src/offset_date_time.rs
parentAdding debian version 1.71.1+dfsg1-2. (diff)
downloadrustc-a0b8f38ab54ac451646aa00cd5e91b6c76f22a84.tar.xz
rustc-a0b8f38ab54ac451646aa00cd5e91b6c76f22a84.zip
Merging upstream version 1.72.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/time/src/offset_date_time.rs')
-rw-r--r--vendor/time/src/offset_date_time.rs24
1 files changed, 24 insertions, 0 deletions
diff --git a/vendor/time/src/offset_date_time.rs b/vendor/time/src/offset_date_time.rs
index 1e342ca8e..d979174e1 100644
--- a/vendor/time/src/offset_date_time.rs
+++ b/vendor/time/src/offset_date_time.rs
@@ -97,6 +97,30 @@ impl OffsetDateTime {
Self(self.0.to_offset(offset))
}
+ /// Convert the `OffsetDateTime` from the current [`UtcOffset`] to the provided [`UtcOffset`],
+ /// returning `None` if the date-time in the resulting offset is invalid.
+ ///
+ /// ```rust
+ /// # use time::PrimitiveDateTime;
+ /// # use time_macros::{datetime, offset};
+ /// assert_eq!(
+ /// datetime!(2000-01-01 0:00 UTC)
+ /// .checked_to_offset(offset!(-1))
+ /// .unwrap()
+ /// .year(),
+ /// 1999,
+ /// );
+ /// assert_eq!(
+ /// PrimitiveDateTime::MAX
+ /// .assume_utc()
+ /// .checked_to_offset(offset!(+1)),
+ /// None,
+ /// );
+ /// ```
+ pub const fn checked_to_offset(self, offset: UtcOffset) -> Option<Self> {
+ Some(Self(const_try_opt!(self.0.checked_to_offset(offset))))
+ }
+
// region: constructors
/// Create an `OffsetDateTime` from the provided Unix timestamp. Calling `.offset()` on the
/// resulting value is guaranteed to return UTC.