diff options
Diffstat (limited to 'vendor/chrono/src/offset/fixed.rs')
-rw-r--r-- | vendor/chrono/src/offset/fixed.rs | 33 |
1 files changed, 22 insertions, 11 deletions
diff --git a/vendor/chrono/src/offset/fixed.rs b/vendor/chrono/src/offset/fixed.rs index 0989dfa5b..246d6666e 100644 --- a/vendor/chrono/src/offset/fixed.rs +++ b/vendor/chrono/src/offset/fixed.rs @@ -6,7 +6,6 @@ use core::fmt; use core::ops::{Add, Sub}; -use num_integer::div_mod_floor; #[cfg(feature = "rkyv")] use rkyv::{Archive, Deserialize, Serialize}; @@ -34,6 +33,7 @@ impl FixedOffset { /// /// Panics on the out-of-bound `secs`. #[deprecated(since = "0.4.23", note = "use `east_opt()` instead")] + #[must_use] pub fn east(secs: i32) -> FixedOffset { FixedOffset::east_opt(secs).expect("FixedOffset::east out of bounds") } @@ -45,14 +45,18 @@ impl FixedOffset { /// /// # Example /// - /// ``` + #[cfg_attr(not(feature = "std"), doc = "```ignore")] + #[cfg_attr(feature = "std", doc = "```")] /// use chrono::{FixedOffset, TimeZone}; /// let hour = 3600; - /// let datetime = FixedOffset::east_opt(5 * hour).unwrap().ymd_opt(2016, 11, 08).unwrap() - /// .and_hms_opt(0, 0, 0).unwrap(); + /// let datetime = FixedOffset::east_opt(5 * hour) + /// .unwrap() + /// .with_ymd_and_hms(2016, 11, 08, 0, 0, 0) + /// .unwrap(); /// assert_eq!(&datetime.to_rfc3339(), "2016-11-08T00:00:00+05:00") /// ``` - pub fn east_opt(secs: i32) -> Option<FixedOffset> { + #[must_use] + pub const fn east_opt(secs: i32) -> Option<FixedOffset> { if -86_400 < secs && secs < 86_400 { Some(FixedOffset { local_minus_utc: secs }) } else { @@ -65,6 +69,7 @@ impl FixedOffset { /// /// Panics on the out-of-bound `secs`. #[deprecated(since = "0.4.23", note = "use `west_opt()` instead")] + #[must_use] pub fn west(secs: i32) -> FixedOffset { FixedOffset::west_opt(secs).expect("FixedOffset::west out of bounds") } @@ -76,14 +81,18 @@ impl FixedOffset { /// /// # Example /// - /// ``` + #[cfg_attr(not(feature = "std"), doc = "```ignore")] + #[cfg_attr(feature = "std", doc = "```")] /// use chrono::{FixedOffset, TimeZone}; /// let hour = 3600; - /// let datetime = FixedOffset::west_opt(5 * hour).unwrap().ymd_opt(2016, 11, 08).unwrap() - /// .and_hms_opt(0, 0, 0).unwrap(); + /// let datetime = FixedOffset::west_opt(5 * hour) + /// .unwrap() + /// .with_ymd_and_hms(2016, 11, 08, 0, 0, 0) + /// .unwrap(); /// assert_eq!(&datetime.to_rfc3339(), "2016-11-08T00:00:00-05:00") /// ``` - pub fn west_opt(secs: i32) -> Option<FixedOffset> { + #[must_use] + pub const fn west_opt(secs: i32) -> Option<FixedOffset> { if -86_400 < secs && secs < 86_400 { Some(FixedOffset { local_minus_utc: -secs }) } else { @@ -136,8 +145,10 @@ impl fmt::Debug for FixedOffset { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { let offset = self.local_minus_utc; let (sign, offset) = if offset < 0 { ('-', -offset) } else { ('+', offset) }; - let (mins, sec) = div_mod_floor(offset, 60); - let (hour, min) = div_mod_floor(mins, 60); + let sec = offset.rem_euclid(60); + let mins = offset.div_euclid(60); + let min = mins.rem_euclid(60); + let hour = mins.div_euclid(60); if sec == 0 { write!(f, "{}{:02}:{:02}", sign, hour, min) } else { |