mirror of
https://github.com/chronotope/chrono.git
synced 2025-09-28 13:31:35 +00:00
Remove num-integer dependency
This commit is contained in:
parent
3bfb6abbbf
commit
e3f591fba3
@ -30,7 +30,6 @@ __doctest = []
|
||||
|
||||
[dependencies]
|
||||
time = { version = "0.1.43", optional = true }
|
||||
num-integer = { version = "0.1.36", default-features = false }
|
||||
num-traits = { version = "0.2", default-features = false }
|
||||
rustc-serialize = { version = "0.3.20", optional = true }
|
||||
serde = { version = "1.0.99", default-features = false, optional = true }
|
||||
|
@ -512,8 +512,6 @@ fn format_inner(
|
||||
) -> fmt::Result {
|
||||
let locale = Locales::new(locale);
|
||||
|
||||
use num_integer::{div_floor, mod_floor};
|
||||
|
||||
match *item {
|
||||
Item::Literal(s) | Item::Space(s) => result.push_str(s),
|
||||
#[cfg(any(feature = "alloc", feature = "std", test))]
|
||||
@ -527,11 +525,11 @@ fn format_inner(
|
||||
|
||||
let (width, v) = match *spec {
|
||||
Year => (4, date.map(|d| i64::from(d.year()))),
|
||||
YearDiv100 => (2, date.map(|d| div_floor(i64::from(d.year()), 100))),
|
||||
YearMod100 => (2, date.map(|d| mod_floor(i64::from(d.year()), 100))),
|
||||
YearDiv100 => (2, date.map(|d| i64::from(d.year()).div_euclid(100))),
|
||||
YearMod100 => (2, date.map(|d| i64::from(d.year()).rem_euclid(100))),
|
||||
IsoYear => (4, date.map(|d| i64::from(d.iso_week().year()))),
|
||||
IsoYearDiv100 => (2, date.map(|d| div_floor(i64::from(d.iso_week().year()), 100))),
|
||||
IsoYearMod100 => (2, date.map(|d| mod_floor(i64::from(d.iso_week().year()), 100))),
|
||||
IsoYearDiv100 => (2, date.map(|d| i64::from(d.iso_week().year()).div_euclid(100))),
|
||||
IsoYearMod100 => (2, date.map(|d| i64::from(d.iso_week().year()).rem_euclid(100))),
|
||||
Month => (2, date.map(|d| i64::from(d.month()))),
|
||||
Day => (2, date.map(|d| i64::from(d.day()))),
|
||||
WeekFromSun => (2, date.map(|d| i64::from(week_from_sun(d)))),
|
||||
|
@ -4,7 +4,6 @@
|
||||
//! A collection of parsed date and time items.
|
||||
//! They can be constructed incrementally while being checked for consistency.
|
||||
|
||||
use num_integer::div_rem;
|
||||
use num_traits::ToPrimitive;
|
||||
|
||||
use super::{ParseResult, IMPOSSIBLE, NOT_ENOUGH, OUT_OF_RANGE};
|
||||
@ -311,7 +310,8 @@ impl Parsed {
|
||||
if y < 0 {
|
||||
return Err(OUT_OF_RANGE);
|
||||
}
|
||||
let (q_, r_) = div_rem(y, 100);
|
||||
let q_ = y / 100;
|
||||
let r_ = y % 100;
|
||||
if q.unwrap_or(q_) == q_ && r.unwrap_or(r_) == r_ {
|
||||
Ok(Some(y))
|
||||
} else {
|
||||
@ -346,8 +346,7 @@ impl Parsed {
|
||||
let verify_ymd = |date: NaiveDate| {
|
||||
let year = date.year();
|
||||
let (year_div_100, year_mod_100) = if year >= 0 {
|
||||
let (q, r) = div_rem(year, 100);
|
||||
(Some(q), Some(r))
|
||||
(Some(year / 100), Some(year % 100))
|
||||
} else {
|
||||
(None, None) // they should be empty to be consistent
|
||||
};
|
||||
@ -367,8 +366,7 @@ impl Parsed {
|
||||
let isoweek = week.week();
|
||||
let weekday = date.weekday();
|
||||
let (isoyear_div_100, isoyear_mod_100) = if isoyear >= 0 {
|
||||
let (q, r) = div_rem(isoyear, 100);
|
||||
(Some(q), Some(r))
|
||||
(Some(isoyear / 100), Some(isoyear % 100))
|
||||
} else {
|
||||
(None, None) // they should be empty to be consistent
|
||||
};
|
||||
|
@ -9,7 +9,6 @@ use core::convert::TryFrom;
|
||||
use core::ops::{Add, AddAssign, RangeInclusive, Sub, SubAssign};
|
||||
use core::{fmt, str};
|
||||
|
||||
use num_integer::div_mod_floor;
|
||||
use num_traits::ToPrimitive;
|
||||
#[cfg(feature = "rkyv")]
|
||||
use rkyv::{Archive, Deserialize, Serialize};
|
||||
@ -2037,6 +2036,10 @@ impl Default for NaiveDate {
|
||||
}
|
||||
}
|
||||
|
||||
fn div_mod_floor(val: i32, div: i32) -> (i32, i32) {
|
||||
(val.div_euclid(div), val.rem_euclid(div))
|
||||
}
|
||||
|
||||
#[cfg(all(test, any(feature = "rustc-serialize", feature = "serde")))]
|
||||
fn test_encodable_json<F, E>(to_string: F)
|
||||
where
|
||||
|
@ -9,7 +9,6 @@ use core::fmt::Write;
|
||||
use core::ops::{Add, AddAssign, Sub, SubAssign};
|
||||
use core::{fmt, str};
|
||||
|
||||
use num_integer::div_mod_floor;
|
||||
use num_traits::ToPrimitive;
|
||||
#[cfg(feature = "rkyv")]
|
||||
use rkyv::{Archive, Deserialize, Serialize};
|
||||
@ -210,7 +209,8 @@ impl NaiveDateTime {
|
||||
#[inline]
|
||||
#[must_use]
|
||||
pub fn from_timestamp_opt(secs: i64, nsecs: u32) -> Option<NaiveDateTime> {
|
||||
let (days, secs) = div_mod_floor(secs, 86_400);
|
||||
let days = secs.div_euclid(86_400);
|
||||
let secs = secs.rem_euclid(86_400);
|
||||
let date = days
|
||||
.to_i32()
|
||||
.and_then(|days| days.checked_add(719_163))
|
||||
|
@ -17,7 +17,6 @@
|
||||
|
||||
use crate::Weekday;
|
||||
use core::{fmt, i32};
|
||||
use num_integer::{div_rem, mod_floor};
|
||||
use num_traits::FromPrimitive;
|
||||
|
||||
/// The internal date representation. This also includes the packed `Mdf` value.
|
||||
@ -95,7 +94,8 @@ static YEAR_DELTAS: [u8; 401] = [
|
||||
];
|
||||
|
||||
pub(super) fn cycle_to_yo(cycle: u32) -> (u32, u32) {
|
||||
let (mut year_mod_400, mut ordinal0) = div_rem(cycle, 365);
|
||||
let mut year_mod_400 = cycle / 365;
|
||||
let mut ordinal0 = cycle % 365;
|
||||
let delta = u32::from(YEAR_DELTAS[year_mod_400 as usize]);
|
||||
if ordinal0 < delta {
|
||||
year_mod_400 -= 1;
|
||||
@ -116,7 +116,7 @@ impl YearFlags {
|
||||
#[inline]
|
||||
#[must_use]
|
||||
pub fn from_year(year: i32) -> YearFlags {
|
||||
let year = mod_floor(year, 400);
|
||||
let year = year.rem_euclid(400);
|
||||
YearFlags::from_year_mod_400(year)
|
||||
}
|
||||
|
||||
|
@ -8,7 +8,6 @@ use core::borrow::Borrow;
|
||||
use core::ops::{Add, AddAssign, Sub, SubAssign};
|
||||
use core::{fmt, str};
|
||||
|
||||
use num_integer::div_mod_floor;
|
||||
#[cfg(feature = "rkyv")]
|
||||
use rkyv::{Archive, Deserialize, Serialize};
|
||||
|
||||
@ -762,8 +761,10 @@ impl NaiveTime {
|
||||
|
||||
/// Returns a triple of the hour, minute and second numbers.
|
||||
fn hms(&self) -> (u32, u32, u32) {
|
||||
let (mins, sec) = div_mod_floor(self.secs, 60);
|
||||
let (hour, min) = div_mod_floor(mins, 60);
|
||||
let sec = self.secs % 60;
|
||||
let mins = self.secs / 60;
|
||||
let min = mins % 60;
|
||||
let hour = mins / 60;
|
||||
(hour, min, sec)
|
||||
}
|
||||
|
||||
|
@ -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};
|
||||
|
||||
@ -142,8 +141,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 {
|
||||
|
@ -462,31 +462,9 @@ impl Error for OutOfRangeError {
|
||||
}
|
||||
}
|
||||
|
||||
// Copied from libnum
|
||||
#[inline]
|
||||
const fn div_mod_floor_64(this: i64, other: i64) -> (i64, i64) {
|
||||
(div_floor_64(this, other), mod_floor_64(this, other))
|
||||
}
|
||||
|
||||
#[inline]
|
||||
const fn div_floor_64(this: i64, other: i64) -> i64 {
|
||||
match div_rem_64(this, other) {
|
||||
(d, r) if (r > 0 && other < 0) || (r < 0 && other > 0) => d - 1,
|
||||
(d, _) => d,
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
const fn mod_floor_64(this: i64, other: i64) -> i64 {
|
||||
match this % other {
|
||||
r if (r > 0 && other < 0) || (r < 0 && other > 0) => r + other,
|
||||
r => r,
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
const fn div_rem_64(this: i64, other: i64) -> (i64, i64) {
|
||||
(this / other, this % other)
|
||||
(this.div_euclid(other), this.rem_euclid(other))
|
||||
}
|
||||
|
||||
#[cfg(feature = "arbitrary")]
|
||||
|
Loading…
x
Reference in New Issue
Block a user