about summary refs log tree commit diff
path: root/src/libstd
diff options
context:
space:
mode:
authorBrian Anderson <banderson@mozilla.com>2014-07-31 17:24:54 -0700
committerBrian Anderson <banderson@mozilla.com>2014-08-13 11:31:48 -0700
commit77cdaf018c98c1a89afcf8382c3f3e90907f49a7 (patch)
treeff8def4d1ca544d550c94cd4939f7ec57cc70551 /src/libstd
parent4475e6a095a8fe4459ac8b854ae2336e47aaafe5 (diff)
downloadrust-77cdaf018c98c1a89afcf8382c3f3e90907f49a7.tar.gz
rust-77cdaf018c98c1a89afcf8382c3f3e90907f49a7.zip
std: Refactor time module a bit
Put `Duration` in `time::duration`, where the two constants can
be called just `MAX` and `MIN`. Reexport from `time`.
This provides more room for the time module to expand.
Diffstat (limited to 'src/libstd')
-rw-r--r--src/libstd/time/duration.rs (renamed from src/libstd/time.rs)30
-rw-r--r--src/libstd/time/mod.rs15
2 files changed, 30 insertions, 15 deletions
diff --git a/src/libstd/time.rs b/src/libstd/time/duration.rs
index 5a374c37cd8..7f31df96b07 100644
--- a/src/libstd/time.rs
+++ b/src/libstd/time/duration.rs
@@ -44,9 +44,9 @@ pub struct Duration {
 }
 
 /// The minimum possible `Duration`.
-pub static MIN_DURATION: Duration = Duration { days: MIN_DAYS, secs: 0, nanos: 0 };
+pub static MIN: Duration = Duration { days: MIN_DAYS, secs: 0, nanos: 0 };
 /// The maximum possible `Duration`.
-pub static MAX_DURATION: Duration = Duration { days: MAX_DAYS, secs: SECS_PER_DAY as u32 - 1,
+pub static MAX: Duration = Duration { days: MAX_DAYS, secs: SECS_PER_DAY as u32 - 1,
                                       nanos: NANOS_PER_SEC as u32 - 1 };
 
 impl Duration {
@@ -274,8 +274,8 @@ impl Duration {
 }
 
 impl num::Bounded for Duration {
-    #[inline] fn min_value() -> Duration { MIN_DURATION }
-    #[inline] fn max_value() -> Duration { MAX_DURATION }
+    #[inline] fn min_value() -> Duration { MIN }
+    #[inline] fn max_value() -> Duration { MAX }
 }
 
 impl num::Zero for Duration {
@@ -496,7 +496,7 @@ fn div_rem_64(this: i64, other: i64) -> (i64, i64) {
 
 #[cfg(test)]
 mod tests {
-    use super::{Duration, MIN_DAYS, MAX_DAYS, MIN_DURATION, MAX_DURATION};
+    use super::{Duration, MIN_DAYS, MAX_DAYS, MIN, MAX};
     use {i32, i64};
     use num::{Zero, CheckedAdd, CheckedSub};
     use option::{Some, None};
@@ -533,8 +533,8 @@ mod tests {
         assert_eq!(Duration::new(-1, -2, -3_004_005).num_days(), -1);
         assert_eq!(Duration::days(i32::MAX).num_days(), i32::MAX);
         assert_eq!(Duration::days(i32::MIN).num_days(), i32::MIN);
-        assert_eq!(MAX_DURATION.num_days(), MAX_DAYS);
-        assert_eq!(MIN_DURATION.num_days(), MIN_DAYS);
+        assert_eq!(MAX.num_days(), MAX_DAYS);
+        assert_eq!(MIN.num_days(), MIN_DAYS);
     }
 
     #[test]
@@ -551,8 +551,8 @@ mod tests {
         assert_eq!(Duration::new(-1, -2, -3_004_005).num_seconds(), -86402);
         assert_eq!(Duration::seconds(i32::MAX).num_seconds(), i32::MAX as i64);
         assert_eq!(Duration::seconds(i32::MIN).num_seconds(), i32::MIN as i64);
-        assert_eq!(MAX_DURATION.num_seconds(), (MAX_DAYS as i64 + 1) * 86400 - 1);
-        assert_eq!(MIN_DURATION.num_seconds(), MIN_DAYS as i64 * 86400);
+        assert_eq!(MAX.num_seconds(), (MAX_DAYS as i64 + 1) * 86400 - 1);
+        assert_eq!(MIN.num_seconds(), MIN_DAYS as i64 * 86400);
     }
 
     #[test]
@@ -569,8 +569,8 @@ mod tests {
         assert_eq!(Duration::new(-1, -2, -3_004_005).num_milliseconds(), -86402_003);
         assert_eq!(Duration::milliseconds(i32::MAX).num_milliseconds(), i32::MAX as i64);
         assert_eq!(Duration::milliseconds(i32::MIN).num_milliseconds(), i32::MIN as i64);
-        assert_eq!(MAX_DURATION.num_milliseconds(), (MAX_DAYS as i64 + 1) * 86400_000 - 1);
-        assert_eq!(MIN_DURATION.num_milliseconds(), MIN_DAYS as i64 * 86400_000);
+        assert_eq!(MAX.num_milliseconds(), (MAX_DAYS as i64 + 1) * 86400_000 - 1);
+        assert_eq!(MIN.num_milliseconds(), MIN_DAYS as i64 * 86400_000);
     }
 
     #[test]
@@ -587,8 +587,8 @@ mod tests {
         assert_eq!(Duration::new(-1, -2, -3_004_005).num_microseconds(), Some(-86402_003_004));
         assert_eq!(Duration::microseconds(i32::MAX).num_microseconds(), Some(i32::MAX as i64));
         assert_eq!(Duration::microseconds(i32::MIN).num_microseconds(), Some(i32::MIN as i64));
-        assert_eq!(MAX_DURATION.num_microseconds(), None);
-        assert_eq!(MIN_DURATION.num_microseconds(), None);
+        assert_eq!(MAX.num_microseconds(), None);
+        assert_eq!(MIN.num_microseconds(), None);
 
         // overflow checks
         static MICROS_PER_DAY: i64 = 86400_000_000;
@@ -610,8 +610,8 @@ mod tests {
         assert_eq!(Duration::new(-1, -2, -3_004_005).num_nanoseconds(), Some(-86402_003_004_005));
         assert_eq!(Duration::nanoseconds(i32::MAX).num_nanoseconds(), Some(i32::MAX as i64));
         assert_eq!(Duration::nanoseconds(i32::MIN).num_nanoseconds(), Some(i32::MIN as i64));
-        assert_eq!(MAX_DURATION.num_nanoseconds(), None);
-        assert_eq!(MIN_DURATION.num_nanoseconds(), None);
+        assert_eq!(MAX.num_nanoseconds(), None);
+        assert_eq!(MIN.num_nanoseconds(), None);
 
         // overflow checks
         static NANOS_PER_DAY: i64 = 86400_000_000_000;
diff --git a/src/libstd/time/mod.rs b/src/libstd/time/mod.rs
new file mode 100644
index 00000000000..436fa5ebdea
--- /dev/null
+++ b/src/libstd/time/mod.rs
@@ -0,0 +1,15 @@
+// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+//! Temporal quantification.
+
+pub use self::duration::Duration;
+
+pub mod duration;