mirror of
https://github.com/chronotope/chrono.git
synced 2025-09-28 21:42:01 +00:00
Remove unnecessary try_opt!() macro
This commit is contained in:
parent
0b7feacb54
commit
a185d3bdfa
@ -241,7 +241,7 @@ impl<Tz: TimeZone> Date<Tz> {
|
||||
/// Returns `None` when it will result in overflow.
|
||||
#[inline]
|
||||
pub fn checked_add_signed(self, rhs: OldDuration) -> Option<Date<Tz>> {
|
||||
let date = try_opt!(self.date.checked_add_signed(rhs));
|
||||
let date = self.date.checked_add_signed(rhs)?;
|
||||
Some(Date { date, offset: self.offset })
|
||||
}
|
||||
|
||||
@ -250,7 +250,7 @@ impl<Tz: TimeZone> Date<Tz> {
|
||||
/// Returns `None` when it will result in overflow.
|
||||
#[inline]
|
||||
pub fn checked_sub_signed(self, rhs: OldDuration) -> Option<Date<Tz>> {
|
||||
let date = try_opt!(self.date.checked_sub_signed(rhs));
|
||||
let date = self.date.checked_sub_signed(rhs)?;
|
||||
Some(Date { date, offset: self.offset })
|
||||
}
|
||||
|
||||
|
@ -324,7 +324,7 @@ impl<Tz: TimeZone> DateTime<Tz> {
|
||||
/// Returns `None` when it will result in overflow.
|
||||
#[inline]
|
||||
pub fn checked_add_signed(self, rhs: OldDuration) -> Option<DateTime<Tz>> {
|
||||
let datetime = try_opt!(self.datetime.checked_add_signed(rhs));
|
||||
let datetime = self.datetime.checked_add_signed(rhs)?;
|
||||
let tz = self.timezone();
|
||||
Some(tz.from_utc_datetime(&datetime))
|
||||
}
|
||||
@ -334,7 +334,7 @@ impl<Tz: TimeZone> DateTime<Tz> {
|
||||
/// Returns `None` when it will result in overflow.
|
||||
#[inline]
|
||||
pub fn checked_sub_signed(self, rhs: OldDuration) -> Option<DateTime<Tz>> {
|
||||
let datetime = try_opt!(self.datetime.checked_sub_signed(rhs));
|
||||
let datetime = self.datetime.checked_sub_signed(rhs)?;
|
||||
let tz = self.timezone();
|
||||
Some(tz.from_utc_datetime(&datetime))
|
||||
}
|
||||
|
10
src/lib.rs
10
src/lib.rs
@ -463,16 +463,6 @@ pub mod prelude {
|
||||
pub use crate::{Offset, TimeZone};
|
||||
}
|
||||
|
||||
// useful throughout the codebase
|
||||
macro_rules! try_opt {
|
||||
($e:expr) => {
|
||||
match $e {
|
||||
Some(v) => v,
|
||||
None => return None,
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
mod date;
|
||||
#[allow(deprecated)]
|
||||
pub use date::{Date, MAX_DATE, MIN_DATE};
|
||||
|
@ -1053,7 +1053,7 @@ impl NaiveDate {
|
||||
let year = self.year();
|
||||
let (mut year_div_400, year_mod_400) = div_mod_floor(year, 400);
|
||||
let cycle = internals::yo_to_cycle(year_mod_400 as u32, self.of().ordinal());
|
||||
let cycle = try_opt!((cycle as i32).checked_add(try_opt!(rhs.num_days().to_i32())));
|
||||
let cycle = (cycle as i32).checked_add(rhs.num_days().to_i32()?)?;
|
||||
let (cycle_div_400y, cycle) = div_mod_floor(cycle, 146_097);
|
||||
year_div_400 += cycle_div_400y;
|
||||
|
||||
@ -1084,7 +1084,7 @@ impl NaiveDate {
|
||||
let year = self.year();
|
||||
let (mut year_div_400, year_mod_400) = div_mod_floor(year, 400);
|
||||
let cycle = internals::yo_to_cycle(year_mod_400 as u32, self.of().ordinal());
|
||||
let cycle = try_opt!((cycle as i32).checked_sub(try_opt!(rhs.num_days().to_i32())));
|
||||
let cycle = (cycle as i32).checked_sub(rhs.num_days().to_i32()?)?;
|
||||
let (cycle_div_400y, cycle) = div_mod_floor(cycle, 146_097);
|
||||
year_div_400 += cycle_div_400y;
|
||||
|
||||
|
@ -529,7 +529,7 @@ impl NaiveDateTime {
|
||||
return None;
|
||||
}
|
||||
|
||||
let date = try_opt!(self.date.checked_add_signed(OldDuration::seconds(rhs)));
|
||||
let date = self.date.checked_add_signed(OldDuration::seconds(rhs))?;
|
||||
Some(NaiveDateTime { date, time })
|
||||
}
|
||||
|
||||
@ -602,7 +602,7 @@ impl NaiveDateTime {
|
||||
return None;
|
||||
}
|
||||
|
||||
let date = try_opt!(self.date.checked_sub_signed(OldDuration::seconds(rhs)));
|
||||
let date = self.date.checked_sub_signed(OldDuration::seconds(rhs))?;
|
||||
Some(NaiveDateTime { date, time })
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user