From 9ccc65aeda50e9230bec6fd29845d5e8678b279f Mon Sep 17 00:00:00 2001 From: Brandon W Maister Date: Sun, 21 Jun 2020 17:49:32 -0400 Subject: [PATCH] Fix oldtime, make it more clear what's going on --- src/lib.rs | 4 ++-- src/oldtime.rs | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 66354f41..ca60ad6a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -421,6 +421,8 @@ extern crate std as alloc; #[cfg(feature="clock")] extern crate time as oldtime; +#[cfg(not(feature="clock"))] +mod oldtime; extern crate num_integer; extern crate num_traits; #[cfg(feature = "rustc-serialize")] @@ -475,8 +477,6 @@ macro_rules! try_opt { } mod div; -#[cfg(not(feature="clock"))] -mod oldtime; pub mod offset; pub mod naive { //! Date and time types unconcerned with timezones. diff --git a/src/oldtime.rs b/src/oldtime.rs index e0930a92..733c4e4a 100644 --- a/src/oldtime.rs +++ b/src/oldtime.rs @@ -133,12 +133,12 @@ impl Duration { } /// Makes a new `Duration` with the given number of seconds and nanoseconds. - /// + /// /// `nanos` in excess of `999_999_999` are carried over into seconds. #[inline] pub fn seconds_nanos(secs: i64, nanos: i32) -> Duration { - let (secs_from_nanos, nanos) = div_mod_floor_64(nanos, NANOS_PER_SEC as i64); - let d = Duration { secs: secs + secs_from_nanos, nanos } + let (secs_from_nanos, nanos) = div_mod_floor_64(nanos.into(), NANOS_PER_SEC as i64); + let d = Duration { secs: secs + secs_from_nanos, nanos: nanos as i32 }; if d < MIN || d > MAX { panic!("Duration::seconds out of bounds"); } @@ -630,7 +630,7 @@ mod tests { fn test_to_std() { assert_eq!(Duration::seconds(1).to_std(), Ok(StdDuration::new(1, 0))); assert_eq!(Duration::seconds(86401).to_std(), Ok(StdDuration::new(86401, 0))); - assert_eq!(Duration::secs_nanos(86401, 86401).to_std(), Ok(StdDuration::new(86401, 86401))); + assert_eq!(Duration::seconds_nanos(86401, 86401).to_std(), Ok(StdDuration::new(86401, 86401))); assert_eq!(Duration::milliseconds(123).to_std(), Ok(StdDuration::new(0, 123000000))); assert_eq!(Duration::milliseconds(123765).to_std(), Ok(StdDuration::new(123, 765000000))); assert_eq!(Duration::nanoseconds(777).to_std(), Ok(StdDuration::new(0, 777)));