Fix oldtime, make it more clear what's going on

This commit is contained in:
Brandon W Maister 2020-06-21 17:49:32 -04:00
parent 2c81fa8c1a
commit 9ccc65aeda
2 changed files with 6 additions and 6 deletions

View File

@ -421,6 +421,8 @@ extern crate std as alloc;
#[cfg(feature="clock")] #[cfg(feature="clock")]
extern crate time as oldtime; extern crate time as oldtime;
#[cfg(not(feature="clock"))]
mod oldtime;
extern crate num_integer; extern crate num_integer;
extern crate num_traits; extern crate num_traits;
#[cfg(feature = "rustc-serialize")] #[cfg(feature = "rustc-serialize")]
@ -475,8 +477,6 @@ macro_rules! try_opt {
} }
mod div; mod div;
#[cfg(not(feature="clock"))]
mod oldtime;
pub mod offset; pub mod offset;
pub mod naive { pub mod naive {
//! Date and time types unconcerned with timezones. //! Date and time types unconcerned with timezones.

View File

@ -133,12 +133,12 @@ impl Duration {
} }
/// Makes a new `Duration` with the given number of seconds and nanoseconds. /// Makes a new `Duration` with the given number of seconds and nanoseconds.
/// ///
/// `nanos` in excess of `999_999_999` are carried over into seconds. /// `nanos` in excess of `999_999_999` are carried over into seconds.
#[inline] #[inline]
pub fn seconds_nanos(secs: i64, nanos: i32) -> Duration { 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 (secs_from_nanos, nanos) = div_mod_floor_64(nanos.into(), NANOS_PER_SEC as i64);
let d = Duration { secs: secs + secs_from_nanos, nanos } let d = Duration { secs: secs + secs_from_nanos, nanos: nanos as i32 };
if d < MIN || d > MAX { if d < MIN || d > MAX {
panic!("Duration::seconds out of bounds"); panic!("Duration::seconds out of bounds");
} }
@ -630,7 +630,7 @@ mod tests {
fn test_to_std() { fn test_to_std() {
assert_eq!(Duration::seconds(1).to_std(), Ok(StdDuration::new(1, 0))); 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::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(123).to_std(), Ok(StdDuration::new(0, 123000000)));
assert_eq!(Duration::milliseconds(123765).to_std(), Ok(StdDuration::new(123, 765000000))); assert_eq!(Duration::milliseconds(123765).to_std(), Ok(StdDuration::new(123, 765000000)));
assert_eq!(Duration::nanoseconds(777).to_std(), Ok(StdDuration::new(0, 777))); assert_eq!(Duration::nanoseconds(777).to_std(), Ok(StdDuration::new(0, 777)));