Fix Clippy lints: unreadable_literal and inconsistent_digit_grouping

Use `_` consistently in long numeric literals.
This commit is contained in:
Brandon W Maister 2017-10-08 17:38:41 -04:00
parent b3adf050f5
commit 268be10d79
9 changed files with 51 additions and 51 deletions

View File

@ -395,7 +395,7 @@ pub fn format<'a, I>(w: &mut fmt::Formatter, date: Option<&NaiveDate>, time: Opt
}; };
if let Some(v) = v { if let Some(v) = v {
if (spec == Year || spec == IsoYear) && !(0 <= v && v < 10000) { if (spec == Year || spec == IsoYear) && !(0 <= v && v < 10_000) {
// non-four-digit years require an explicit sign as per ISO 8601 // non-four-digit years require an explicit sign as per ISO 8601
match pad { match pad {
Pad::None => try!(write!(w, "{:+}", v)), Pad::None => try!(write!(w, "{:+}", v)),

View File

@ -180,7 +180,7 @@ fn parse_rfc3339<'a>(parsed: &mut Parsed, mut s: &'a str) -> ParseResult<(&'a st
} }
let offset = try_consume!(scan::timezone_offset_zulu(s, |s| scan::char(s, b':'))); let offset = try_consume!(scan::timezone_offset_zulu(s, |s| scan::char(s, b':')));
if offset <= -86400 || offset >= 86400 { return Err(OUT_OF_RANGE); } if offset <= -86_400 || offset >= 86_400 { return Err(OUT_OF_RANGE); }
try!(parsed.set_offset(offset as i64)); try!(parsed.set_offset(offset as i64));
Ok((s, ())) Ok((s, ()))

View File

@ -1041,7 +1041,7 @@ mod tests {
minute: 42, second: 4, nanosecond: 12_345_678, offset: -9876), minute: 42, second: 4, nanosecond: 12_345_678, offset: -9876),
ymdhmsn(2014,12,31, 1,42,4,12_345_678, -9876)); ymdhmsn(2014,12,31, 1,42,4,12_345_678, -9876));
assert_eq!(parse!(year: 2015, ordinal: 1, hour_div_12: 0, hour_mod_12: 4, assert_eq!(parse!(year: 2015, ordinal: 1, hour_div_12: 0, hour_mod_12: 4,
minute: 26, second: 40, nanosecond: 12_345_678, offset: 86400), minute: 26, second: 40, nanosecond: 12_345_678, offset: 86_400),
Err(OUT_OF_RANGE)); // `FixedOffset` does not support such huge offset Err(OUT_OF_RANGE)); // `FixedOffset` does not support such huge offset
} }

View File

@ -842,7 +842,7 @@ pub trait Datelike: Sized {
if year < 0 { if year < 0 {
let excess = 1 + (-year) / 400; let excess = 1 + (-year) / 400;
year += excess * 400; year += excess * 400;
ndays -= excess * 146097; ndays -= excess * 146_097;
} }
let div_100 = year / 100; let div_100 = year / 100;
ndays += ((year * 1461) >> 2) - div_100 + (div_100 >> 2); ndays += ((year * 1461) >> 2) - div_100 + (div_100 >> 2);

View File

@ -400,7 +400,7 @@ impl NaiveDate {
/// ~~~~ /// ~~~~
pub fn from_num_days_from_ce_opt(days: i32) -> Option<NaiveDate> { pub fn from_num_days_from_ce_opt(days: i32) -> Option<NaiveDate> {
let days = days + 365; // make December 31, 1 BCE equal to day 0 let days = days + 365; // make December 31, 1 BCE equal to day 0
let (year_div_400, cycle) = div_mod_floor(days, 146097); let (year_div_400, cycle) = div_mod_floor(days, 146_097);
let (year_mod_400, ordinal) = internals::cycle_to_yo(cycle as u32); let (year_mod_400, ordinal) = internals::cycle_to_yo(cycle as u32);
let flags = YearFlags::from_year_mod_400(year_mod_400 as i32); let flags = YearFlags::from_year_mod_400(year_mod_400 as i32);
NaiveDate::from_of(year_div_400 * 400 + year_mod_400 as i32, NaiveDate::from_of(year_div_400 * 400 + year_mod_400 as i32,
@ -683,7 +683,7 @@ impl NaiveDate {
/// Returns the packed ordinal-flags. /// Returns the packed ordinal-flags.
#[inline] #[inline]
fn of(&self) -> Of { fn of(&self) -> Of {
Of((self.ymdf & 0b1111_11111_1111) as u32) Of((self.ymdf & 0b1_1111_1111_1111) as u32)
} }
/// Makes a new `NaiveDate` with the packed month-day-flags changed. /// Makes a new `NaiveDate` with the packed month-day-flags changed.
@ -701,7 +701,7 @@ impl NaiveDate {
fn with_of(&self, of: Of) -> Option<NaiveDate> { fn with_of(&self, of: Of) -> Option<NaiveDate> {
if of.valid() { if of.valid() {
let Of(of) = of; let Of(of) = of;
Some(NaiveDate { ymdf: (self.ymdf & !0b111111111_1111) | of as DateImpl }) Some(NaiveDate { ymdf: (self.ymdf & !0b1_1111_1111_1111) | of as DateImpl })
} else { } else {
None None
} }
@ -808,7 +808,7 @@ impl NaiveDate {
let (mut year_div_400, year_mod_400) = div_mod_floor(year, 400); 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 = 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 = try_opt!((cycle as i32).checked_add(try_opt!(rhs.num_days().to_i32())));
let (cycle_div_400y, cycle) = div_mod_floor(cycle, 146097); let (cycle_div_400y, cycle) = div_mod_floor(cycle, 146_097);
year_div_400 += cycle_div_400y; year_div_400 += cycle_div_400y;
let (year_mod_400, ordinal) = internals::cycle_to_yo(cycle as u32); let (year_mod_400, ordinal) = internals::cycle_to_yo(cycle as u32);
@ -844,7 +844,7 @@ impl NaiveDate {
let (mut year_div_400, year_mod_400) = div_mod_floor(year, 400); 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 = 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 = try_opt!((cycle as i32).checked_sub(try_opt!(rhs.num_days().to_i32())));
let (cycle_div_400y, cycle) = div_mod_floor(cycle, 146097); let (cycle_div_400y, cycle) = div_mod_floor(cycle, 146_097);
year_div_400 += cycle_div_400y; year_div_400 += cycle_div_400y;
let (year_mod_400, ordinal) = internals::cycle_to_yo(cycle as u32); let (year_mod_400, ordinal) = internals::cycle_to_yo(cycle as u32);
@ -885,7 +885,7 @@ impl NaiveDate {
let (year2_div_400, year2_mod_400) = div_mod_floor(year2, 400); let (year2_div_400, year2_mod_400) = div_mod_floor(year2, 400);
let cycle1 = internals::yo_to_cycle(year1_mod_400 as u32, self.of().ordinal()) as i64; let cycle1 = internals::yo_to_cycle(year1_mod_400 as u32, self.of().ordinal()) as i64;
let cycle2 = internals::yo_to_cycle(year2_mod_400 as u32, rhs.of().ordinal()) as i64; let cycle2 = internals::yo_to_cycle(year2_mod_400 as u32, rhs.of().ordinal()) as i64;
OldDuration::days((year1_div_400 as i64 - year2_div_400 as i64) * 146097 + OldDuration::days((year1_div_400 as i64 - year2_div_400 as i64) * 146_097 +
(cycle1 - cycle2)) (cycle1 - cycle2))
} }

View File

@ -133,8 +133,8 @@ impl NaiveDateTime {
/// ~~~~ /// ~~~~
#[inline] #[inline]
pub fn from_timestamp_opt(secs: i64, nsecs: u32) -> Option<NaiveDateTime> { pub fn from_timestamp_opt(secs: i64, nsecs: u32) -> Option<NaiveDateTime> {
let (days, secs) = div_mod_floor(secs, 86400); let (days, secs) = div_mod_floor(secs, 86_400);
let date = days.to_i32().and_then(|days| days.checked_add(719163)) let date = days.to_i32().and_then(|days| days.checked_add(719_163))
.and_then(NaiveDate::from_num_days_from_ce_opt); .and_then(NaiveDate::from_num_days_from_ce_opt);
let time = NaiveTime::from_num_seconds_from_midnight_opt(secs as u32, nsecs); let time = NaiveTime::from_num_seconds_from_midnight_opt(secs as u32, nsecs);
match (date, time) { match (date, time) {
@ -260,7 +260,7 @@ impl NaiveDateTime {
pub fn timestamp(&self) -> i64 { pub fn timestamp(&self) -> i64 {
let ndays = self.date.num_days_from_ce() as i64; let ndays = self.date.num_days_from_ce() as i64;
let nseconds = self.time.num_seconds_from_midnight() as i64; let nseconds = self.time.num_seconds_from_midnight() as i64;
(ndays - 719163) * 86400 + nseconds (ndays - 719_163) * 86_400 + nseconds
} }
/// Returns the number of non-leap *milliseconds* since midnight on January 1, 1970. /// Returns the number of non-leap *milliseconds* since midnight on January 1, 1970.
@ -381,7 +381,7 @@ impl NaiveDateTime {
/// Some(hms(3, 5, 6))); /// Some(hms(3, 5, 6)));
/// assert_eq!(hms(3, 5, 7).checked_add_signed(Duration::seconds(3600 + 60)), /// assert_eq!(hms(3, 5, 7).checked_add_signed(Duration::seconds(3600 + 60)),
/// Some(hms(4, 6, 7))); /// Some(hms(4, 6, 7)));
/// assert_eq!(hms(3, 5, 7).checked_add_signed(Duration::seconds(86400)), /// assert_eq!(hms(3, 5, 7).checked_add_signed(Duration::seconds(86_400)),
/// Some(from_ymd(2016, 7, 9).and_hms(3, 5, 7))); /// Some(from_ymd(2016, 7, 9).and_hms(3, 5, 7)));
/// ///
/// let hmsm = |h, m, s, milli| d.and_hms_milli(h, m, s, milli); /// let hmsm = |h, m, s, milli| d.and_hms_milli(h, m, s, milli);
@ -467,7 +467,7 @@ impl NaiveDateTime {
/// Some(hms(3, 5, 8))); /// Some(hms(3, 5, 8)));
/// assert_eq!(hms(3, 5, 7).checked_sub_signed(Duration::seconds(3600 + 60)), /// assert_eq!(hms(3, 5, 7).checked_sub_signed(Duration::seconds(3600 + 60)),
/// Some(hms(2, 4, 7))); /// Some(hms(2, 4, 7)));
/// assert_eq!(hms(3, 5, 7).checked_sub_signed(Duration::seconds(86400)), /// assert_eq!(hms(3, 5, 7).checked_sub_signed(Duration::seconds(86_400)),
/// Some(from_ymd(2016, 7, 7).and_hms(3, 5, 7))); /// Some(from_ymd(2016, 7, 7).and_hms(3, 5, 7)));
/// ///
/// let hmsm = |h, m, s, milli| d.and_hms_milli(h, m, s, milli); /// let hmsm = |h, m, s, milli| d.and_hms_milli(h, m, s, milli);
@ -546,7 +546,7 @@ impl NaiveDateTime {
/// // July 8 is 190th day in the year 2016 /// // July 8 is 190th day in the year 2016
/// let d0 = from_ymd(2016, 1, 1); /// let d0 = from_ymd(2016, 1, 1);
/// assert_eq!(d.and_hms_milli(0, 7, 6, 500).signed_duration_since(d0.and_hms(0, 0, 0)), /// assert_eq!(d.and_hms_milli(0, 7, 6, 500).signed_duration_since(d0.and_hms(0, 0, 0)),
/// Duration::seconds(189 * 86400 + 7 * 60 + 6) + Duration::milliseconds(500)); /// Duration::seconds(189 * 86_400 + 7 * 60 + 6) + Duration::milliseconds(500));
/// # } /// # }
/// ~~~~ /// ~~~~
/// ///
@ -1163,7 +1163,7 @@ impl hash::Hash for NaiveDateTime {
/// assert_eq!(hms(3, 5, 7) + Duration::seconds(1), hms(3, 5, 8)); /// assert_eq!(hms(3, 5, 7) + Duration::seconds(1), hms(3, 5, 8));
/// assert_eq!(hms(3, 5, 7) + Duration::seconds(-1), hms(3, 5, 6)); /// assert_eq!(hms(3, 5, 7) + Duration::seconds(-1), hms(3, 5, 6));
/// assert_eq!(hms(3, 5, 7) + Duration::seconds(3600 + 60), hms(4, 6, 7)); /// assert_eq!(hms(3, 5, 7) + Duration::seconds(3600 + 60), hms(4, 6, 7));
/// assert_eq!(hms(3, 5, 7) + Duration::seconds(86400), /// assert_eq!(hms(3, 5, 7) + Duration::seconds(86_400),
/// from_ymd(2016, 7, 9).and_hms(3, 5, 7)); /// from_ymd(2016, 7, 9).and_hms(3, 5, 7));
/// assert_eq!(hms(3, 5, 7) + Duration::days(365), /// assert_eq!(hms(3, 5, 7) + Duration::days(365),
/// from_ymd(2017, 7, 8).and_hms(3, 5, 7)); /// from_ymd(2017, 7, 8).and_hms(3, 5, 7));
@ -1235,7 +1235,7 @@ impl AddAssign<OldDuration> for NaiveDateTime {
/// assert_eq!(hms(3, 5, 7) - Duration::seconds(1), hms(3, 5, 6)); /// assert_eq!(hms(3, 5, 7) - Duration::seconds(1), hms(3, 5, 6));
/// assert_eq!(hms(3, 5, 7) - Duration::seconds(-1), hms(3, 5, 8)); /// assert_eq!(hms(3, 5, 7) - Duration::seconds(-1), hms(3, 5, 8));
/// assert_eq!(hms(3, 5, 7) - Duration::seconds(3600 + 60), hms(2, 4, 7)); /// assert_eq!(hms(3, 5, 7) - Duration::seconds(3600 + 60), hms(2, 4, 7));
/// assert_eq!(hms(3, 5, 7) - Duration::seconds(86400), /// assert_eq!(hms(3, 5, 7) - Duration::seconds(86_400),
/// from_ymd(2016, 7, 7).and_hms(3, 5, 7)); /// from_ymd(2016, 7, 7).and_hms(3, 5, 7));
/// assert_eq!(hms(3, 5, 7) - Duration::days(365), /// assert_eq!(hms(3, 5, 7) - Duration::days(365),
/// from_ymd(2015, 7, 9).and_hms(3, 5, 7)); /// from_ymd(2015, 7, 9).and_hms(3, 5, 7));
@ -1807,9 +1807,9 @@ mod tests {
check((2014,5,6, 7,8,9), Duration::seconds(3600 + 60 + 1), Some((2014,5,6, 8,9,10))); check((2014,5,6, 7,8,9), Duration::seconds(3600 + 60 + 1), Some((2014,5,6, 8,9,10)));
check((2014,5,6, 7,8,9), Duration::seconds(-(3600 + 60 + 1)), Some((2014,5,6, 6,7,8))); check((2014,5,6, 7,8,9), Duration::seconds(-(3600 + 60 + 1)), Some((2014,5,6, 6,7,8)));
check((2014,5,6, 7,8,9), Duration::seconds(86399), Some((2014,5,7, 7,8,8))); check((2014,5,6, 7,8,9), Duration::seconds(86399), Some((2014,5,7, 7,8,8)));
check((2014,5,6, 7,8,9), Duration::seconds(86400 * 10), Some((2014,5,16, 7,8,9))); check((2014,5,6, 7,8,9), Duration::seconds(86_400 * 10), Some((2014,5,16, 7,8,9)));
check((2014,5,6, 7,8,9), Duration::seconds(-86400 * 10), Some((2014,4,26, 7,8,9))); check((2014,5,6, 7,8,9), Duration::seconds(-86_400 * 10), Some((2014,4,26, 7,8,9)));
check((2014,5,6, 7,8,9), Duration::seconds(86400 * 10), Some((2014,5,16, 7,8,9))); check((2014,5,6, 7,8,9), Duration::seconds(86_400 * 10), Some((2014,5,16, 7,8,9)));
// overflow check // overflow check
// assumes that we have correct values for MAX/MIN_DAYS_FROM_YEAR_0 from `naive::date`. // assumes that we have correct values for MAX/MIN_DAYS_FROM_YEAR_0 from `naive::date`.
@ -1818,7 +1818,7 @@ mod tests {
check((0,1,1, 0,0,0), max_days_from_year_0, Some((MAX_DATE.year(),12,31, 0,0,0))); check((0,1,1, 0,0,0), max_days_from_year_0, Some((MAX_DATE.year(),12,31, 0,0,0)));
check((0,1,1, 0,0,0), max_days_from_year_0 + Duration::seconds(86399), check((0,1,1, 0,0,0), max_days_from_year_0 + Duration::seconds(86399),
Some((MAX_DATE.year(),12,31, 23,59,59))); Some((MAX_DATE.year(),12,31, 23,59,59)));
check((0,1,1, 0,0,0), max_days_from_year_0 + Duration::seconds(86400), None); check((0,1,1, 0,0,0), max_days_from_year_0 + Duration::seconds(86_400), None);
check((0,1,1, 0,0,0), Duration::max_value(), None); check((0,1,1, 0,0,0), Duration::max_value(), None);
let min_days_from_year_0 = MIN_DATE.signed_duration_since(NaiveDate::from_ymd(0,1,1)); let min_days_from_year_0 = MIN_DATE.signed_duration_since(NaiveDate::from_ymd(0,1,1));

View File

@ -136,7 +136,7 @@ impl YearFlags {
#[inline] #[inline]
pub fn nisoweeks(&self) -> u32 { pub fn nisoweeks(&self) -> u32 {
let YearFlags(flags) = *self; let YearFlags(flags) = *self;
52 + ((0b00000100_00000110 >> flags as usize) & 1) 52 + ((0b0000_0100_0000_0110 >> flags as usize) & 1)
} }
} }
@ -425,20 +425,20 @@ impl Mdf {
pub fn with_month(&self, month: u32) -> Mdf { pub fn with_month(&self, month: u32) -> Mdf {
let month = Mdf::clamp_month(month); let month = Mdf::clamp_month(month);
let Mdf(mdf) = *self; let Mdf(mdf) = *self;
Mdf((mdf & 0b11111_1111) | (month << 9)) Mdf((mdf & 0b1_1111_1111) | (month << 9))
} }
#[inline] #[inline]
pub fn day(&self) -> u32 { pub fn day(&self) -> u32 {
let Mdf(mdf) = *self; let Mdf(mdf) = *self;
(mdf >> 4) & 0b11111 (mdf >> 4) & 0b1_1111
} }
#[inline] #[inline]
pub fn with_day(&self, day: u32) -> Mdf { pub fn with_day(&self, day: u32) -> Mdf {
let day = Mdf::clamp_day(day); let day = Mdf::clamp_day(day);
let Mdf(mdf) = *self; let Mdf(mdf) = *self;
Mdf((mdf & !0b11111_0000) | (day << 4)) Mdf((mdf & !0b1_1111_0000) | (day << 4))
} }
#[inline] #[inline]
@ -463,7 +463,7 @@ impl fmt::Debug for Mdf {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let Mdf(mdf) = *self; let Mdf(mdf) = *self;
write!(f, "Mdf(({} << 9) | ({} << 4) | {:#04o} /*{:?}*/)", write!(f, "Mdf(({} << 9) | ({} << 4) | {:#04o} /*{:?}*/)",
mdf >> 9, (mdf >> 4) & 0b11111, mdf & 0b1111, YearFlags((mdf & 0b1111) as u8)) mdf >> 9, (mdf >> 4) & 0b1_1111, mdf & 0b1111, YearFlags((mdf & 0b1111) as u8))
} }
} }

View File

@ -420,12 +420,12 @@ impl NaiveTime {
/// assert!(from_nsecs_opt(0, 0).is_some()); /// assert!(from_nsecs_opt(0, 0).is_some());
/// assert!(from_nsecs_opt(86399, 999_999_999).is_some()); /// assert!(from_nsecs_opt(86399, 999_999_999).is_some());
/// assert!(from_nsecs_opt(86399, 1_999_999_999).is_some()); // a leap second after 23:59:59 /// assert!(from_nsecs_opt(86399, 1_999_999_999).is_some()); // a leap second after 23:59:59
/// assert!(from_nsecs_opt(86400, 0).is_none()); /// assert!(from_nsecs_opt(86_400, 0).is_none());
/// assert!(from_nsecs_opt(86399, 2_000_000_000).is_none()); /// assert!(from_nsecs_opt(86399, 2_000_000_000).is_none());
/// ~~~~ /// ~~~~
#[inline] #[inline]
pub fn from_num_seconds_from_midnight_opt(secs: u32, nano: u32) -> Option<NaiveTime> { pub fn from_num_seconds_from_midnight_opt(secs: u32, nano: u32) -> Option<NaiveTime> {
if secs >= 86400 || nano >= 2_000_000_000 { return None; } if secs >= 86_400 || nano >= 2_000_000_000 { return None; }
Some(NaiveTime { secs: secs, frac: nano }) Some(NaiveTime { secs: secs, frac: nano })
} }
@ -513,9 +513,9 @@ impl NaiveTime {
/// assert_eq!(from_hms(3, 4, 5).overflowing_add_signed(Duration::hours(11)), /// assert_eq!(from_hms(3, 4, 5).overflowing_add_signed(Duration::hours(11)),
/// (from_hms(14, 4, 5), 0)); /// (from_hms(14, 4, 5), 0));
/// assert_eq!(from_hms(3, 4, 5).overflowing_add_signed(Duration::hours(23)), /// assert_eq!(from_hms(3, 4, 5).overflowing_add_signed(Duration::hours(23)),
/// (from_hms(2, 4, 5), 86400)); /// (from_hms(2, 4, 5), 86_400));
/// assert_eq!(from_hms(3, 4, 5).overflowing_add_signed(Duration::hours(-7)), /// assert_eq!(from_hms(3, 4, 5).overflowing_add_signed(Duration::hours(-7)),
/// (from_hms(20, 4, 5), -86400)); /// (from_hms(20, 4, 5), -86_400));
/// # } /// # }
/// ~~~~ /// ~~~~
#[cfg_attr(feature = "cargo-clippy", allow(cyclomatic_complexity))] #[cfg_attr(feature = "cargo-clippy", allow(cyclomatic_complexity))]
@ -541,23 +541,23 @@ impl NaiveTime {
return (NaiveTime { secs: secs, frac: frac }, 0); return (NaiveTime { secs: secs, frac: frac }, 0);
} }
} }
debug_assert!(secs <= 86400); debug_assert!(secs <= 86_400);
debug_assert!(frac < 1_000_000_000); debug_assert!(frac < 1_000_000_000);
let rhssecs = rhs.num_seconds(); let rhssecs = rhs.num_seconds();
let rhsfrac = (rhs - OldDuration::seconds(rhssecs)).num_nanoseconds().unwrap(); let rhsfrac = (rhs - OldDuration::seconds(rhssecs)).num_nanoseconds().unwrap();
debug_assert_eq!(OldDuration::seconds(rhssecs) + OldDuration::nanoseconds(rhsfrac), rhs); debug_assert_eq!(OldDuration::seconds(rhssecs) + OldDuration::nanoseconds(rhsfrac), rhs);
let rhssecsinday = rhssecs % 86400; let rhssecsinday = rhssecs % 86_400;
let mut morerhssecs = rhssecs - rhssecsinday; let mut morerhssecs = rhssecs - rhssecsinday;
let rhssecs = rhssecsinday as i32; let rhssecs = rhssecsinday as i32;
let rhsfrac = rhsfrac as i32; let rhsfrac = rhsfrac as i32;
debug_assert!(-86400 < rhssecs && rhssecs < 86400); debug_assert!(-86_400 < rhssecs && rhssecs < 86_400);
debug_assert_eq!(morerhssecs % 86400, 0); debug_assert_eq!(morerhssecs % 86_400, 0);
debug_assert!(-1_000_000_000 < rhsfrac && rhsfrac < 1_000_000_000); debug_assert!(-1_000_000_000 < rhsfrac && rhsfrac < 1_000_000_000);
let mut secs = secs as i32 + rhssecs; let mut secs = secs as i32 + rhssecs;
let mut frac = frac as i32 + rhsfrac; let mut frac = frac as i32 + rhsfrac;
debug_assert!(-86400 < secs && secs < 2 * 86400); debug_assert!(-86_400 < secs && secs < 2 * 86_400);
debug_assert!(-1_000_000_000 < frac && frac < 2_000_000_000); debug_assert!(-1_000_000_000 < frac && frac < 2_000_000_000);
if frac < 0 { if frac < 0 {
@ -567,17 +567,17 @@ impl NaiveTime {
frac -= 1_000_000_000; frac -= 1_000_000_000;
secs += 1; secs += 1;
} }
debug_assert!(-86400 <= secs && secs < 2 * 86400); debug_assert!(-86_400 <= secs && secs < 2 * 86_400);
debug_assert!(0 <= frac && frac < 1_000_000_000); debug_assert!(0 <= frac && frac < 1_000_000_000);
if secs < 0 { if secs < 0 {
secs += 86400; secs += 86_400;
morerhssecs -= 86400; morerhssecs -= 86_400;
} else if secs >= 86400 { } else if secs >= 86_400 {
secs -= 86400; secs -= 86_400;
morerhssecs += 86400; morerhssecs += 86_400;
} }
debug_assert!(0 <= secs && secs < 86400); debug_assert!(0 <= secs && secs < 86_400);
(NaiveTime { secs: secs as u32, frac: frac as u32 }, morerhssecs) (NaiveTime { secs: secs as u32, frac: frac as u32 }, morerhssecs)
} }
@ -599,9 +599,9 @@ impl NaiveTime {
/// assert_eq!(from_hms(3, 4, 5).overflowing_sub_signed(Duration::hours(2)), /// assert_eq!(from_hms(3, 4, 5).overflowing_sub_signed(Duration::hours(2)),
/// (from_hms(1, 4, 5), 0)); /// (from_hms(1, 4, 5), 0));
/// assert_eq!(from_hms(3, 4, 5).overflowing_sub_signed(Duration::hours(17)), /// assert_eq!(from_hms(3, 4, 5).overflowing_sub_signed(Duration::hours(17)),
/// (from_hms(10, 4, 5), 86400)); /// (from_hms(10, 4, 5), 86_400));
/// assert_eq!(from_hms(3, 4, 5).overflowing_sub_signed(Duration::hours(-22)), /// assert_eq!(from_hms(3, 4, 5).overflowing_sub_signed(Duration::hours(-22)),
/// (from_hms(1, 4, 5), -86400)); /// (from_hms(1, 4, 5), -86_400));
/// # } /// # }
/// ~~~~ /// ~~~~
#[inline] #[inline]
@ -1516,15 +1516,15 @@ mod tests {
assert_eq!(hmsm(3, 4, 5, 678).overflowing_add_signed(Duration::hours(11)), assert_eq!(hmsm(3, 4, 5, 678).overflowing_add_signed(Duration::hours(11)),
(hmsm(14, 4, 5, 678), 0)); (hmsm(14, 4, 5, 678), 0));
assert_eq!(hmsm(3, 4, 5, 678).overflowing_add_signed(Duration::hours(23)), assert_eq!(hmsm(3, 4, 5, 678).overflowing_add_signed(Duration::hours(23)),
(hmsm(2, 4, 5, 678), 86400)); (hmsm(2, 4, 5, 678), 86_400));
assert_eq!(hmsm(3, 4, 5, 678).overflowing_add_signed(Duration::hours(-7)), assert_eq!(hmsm(3, 4, 5, 678).overflowing_add_signed(Duration::hours(-7)),
(hmsm(20, 4, 5, 678), -86400)); (hmsm(20, 4, 5, 678), -86_400));
// overflowing_add_signed with leap seconds may be counter-intuitive // overflowing_add_signed with leap seconds may be counter-intuitive
assert_eq!(hmsm(3, 4, 5, 1_678).overflowing_add_signed(Duration::days(1)), assert_eq!(hmsm(3, 4, 5, 1_678).overflowing_add_signed(Duration::days(1)),
(hmsm(3, 4, 5, 678), 86400)); (hmsm(3, 4, 5, 678), 86_400));
assert_eq!(hmsm(3, 4, 5, 1_678).overflowing_add_signed(Duration::days(-1)), assert_eq!(hmsm(3, 4, 5, 1_678).overflowing_add_signed(Duration::days(-1)),
(hmsm(3, 4, 6, 678), -86400)); (hmsm(3, 4, 6, 678), -86_400));
} }
#[test] #[test]

View File

@ -48,7 +48,7 @@ impl FixedOffset {
/// ///
/// Returns `None` on the out-of-bound `secs`. /// Returns `None` on the out-of-bound `secs`.
pub fn east_opt(secs: i32) -> Option<FixedOffset> { pub fn east_opt(secs: i32) -> Option<FixedOffset> {
if -86400 < secs && secs < 86400 { if -86_400 < secs && secs < 86_400 {
Some(FixedOffset { local_minus_utc: secs }) Some(FixedOffset { local_minus_utc: secs })
} else { } else {
None None
@ -78,7 +78,7 @@ impl FixedOffset {
/// ///
/// Returns `None` on the out-of-bound `secs`. /// Returns `None` on the out-of-bound `secs`.
pub fn west_opt(secs: i32) -> Option<FixedOffset> { pub fn west_opt(secs: i32) -> Option<FixedOffset> {
if -86400 < secs && secs < 86400 { if -86_400 < secs && secs < 86_400 {
Some(FixedOffset { local_minus_utc: -secs }) Some(FixedOffset { local_minus_utc: -secs })
} else { } else {
None None