diff --git a/CHANGELOG.md b/CHANGELOG.md index da265c7bc6..1159d0790a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,10 @@ Versions with only mechanical changes will be omitted from the following list. ## 0.4.14 (unreleased) +## Improvements + +* Added MIN and MAX values for `NaiveTime`, `NaiveDateTime` and `DateTime<Utc>`. + ## 0.4.13 diff --git a/src/datetime.rs b/src/datetime.rs index 0c0a97753d..c7e6061c47 100644 --- a/src/datetime.rs +++ b/src/datetime.rs @@ -21,7 +21,7 @@ use core::borrow::Borrow; use format::DelayedFormat; use format::{parse, ParseError, ParseResult, Parsed, StrftimeItems}; use format::{Fixed, Item}; -use naive::{IsoWeek, NaiveDateTime, NaiveTime}; +use naive::{self, IsoWeek, NaiveDateTime, NaiveTime}; #[cfg(feature = "clock")] use offset::Local; use offset::{FixedOffset, Offset, TimeZone, Utc}; @@ -70,6 +70,11 @@ pub struct DateTime<Tz: TimeZone> { offset: Tz::Offset, } +/// The minimum possilbe `DateTime<Utc>`. +pub const MIN_DATETIME: DateTime<Utc> = DateTime { datetime: naive::MIN_DATETIME, offset: Utc }; +/// The maximum possible `DateTime<Utc>`. +pub const MAX_DATETIME: DateTime<Utc> = DateTime { datetime: naive::MAX_DATETIME, offset: Utc }; + impl<Tz: TimeZone> DateTime<Tz> { /// Makes a new `DateTime` with given *UTC* datetime and offset. /// The local datetime should be constructed via the `TimeZone` trait. diff --git a/src/lib.rs b/src/lib.rs index d062143e9e..8bbcdb50e6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -450,7 +450,7 @@ pub use oldtime::Duration; pub use date::{Date, MAX_DATE, MIN_DATE}; #[cfg(feature = "rustc-serialize")] pub use datetime::rustc_serialize::TsSeconds; -pub use datetime::{DateTime, SecondsFormat}; +pub use datetime::{DateTime, SecondsFormat, MAX_DATETIME, MIN_DATETIME}; pub use format::{ParseError, ParseResult}; #[doc(no_inline)] pub use naive::{IsoWeek, NaiveDate, NaiveDateTime, NaiveTime}; @@ -511,7 +511,7 @@ pub mod naive { #[cfg(feature = "rustc-serialize")] #[allow(deprecated)] pub use self::datetime::rustc_serialize::TsSeconds; - pub use self::datetime::NaiveDateTime; + pub use self::datetime::{NaiveDateTime, MAX_DATETIME, MIN_DATETIME}; pub use self::isoweek::IsoWeek; pub use self::time::NaiveTime; diff --git a/src/naive/datetime.rs b/src/naive/datetime.rs index d40ff20f08..a768609cfc 100644 --- a/src/naive/datetime.rs +++ b/src/naive/datetime.rs @@ -15,6 +15,8 @@ use div::div_mod_floor; use format::DelayedFormat; use format::{parse, ParseError, ParseResult, Parsed, StrftimeItems}; use format::{Fixed, Item, Numeric, Pad}; +use naive::date::{MAX_DATE, MIN_DATE}; +use naive::time::{MAX_TIME, MIN_TIME}; use naive::{IsoWeek, NaiveDate, NaiveTime}; use {Datelike, Timelike, Weekday}; @@ -26,6 +28,11 @@ use {Datelike, Timelike, Weekday}; /// touching that call when we are already sure that it WILL overflow... const MAX_SECS_BITS: usize = 44; +/// The minimum possible `NaiveDateTime`. +pub const MIN_DATETIME: NaiveDateTime = NaiveDateTime { date: MIN_DATE, time: MIN_TIME }; +/// The maximum possible `NaiveDateTime`. +pub const MAX_DATETIME: NaiveDateTime = NaiveDateTime { date: MAX_DATE, time: MAX_TIME }; + /// ISO 8601 combined date and time without timezone. /// /// # Example diff --git a/src/naive/time.rs b/src/naive/time.rs index d0eebd328b..71072cf9e6 100644 --- a/src/naive/time.rs +++ b/src/naive/time.rs @@ -16,6 +16,9 @@ use format::{parse, ParseError, ParseResult, Parsed, StrftimeItems}; use format::{Fixed, Item, Numeric, Pad}; use Timelike; +pub const MIN_TIME: NaiveTime = NaiveTime { secs: 0, frac: 0 }; +pub const MAX_TIME: NaiveTime = NaiveTime { secs: 23 * 3600 + 59 * 60 + 59, frac: 999_999_999 }; + /// ISO 8601 time without timezone. /// Allows for the nanosecond precision and optional leap second representation. ///