renamed `chrono:📅:{MIN,MAX}` to `chrono:📅:{MINZ,MAXZ}`.

this is because we are going to add `MIN` and `MAX` for
timezone-aware `Date`s later.
This commit is contained in:
Kang Seonghoon 2014-07-25 19:24:32 +09:00
parent 4dbd00dca2
commit 9300f2481c
3 changed files with 11 additions and 9 deletions

View File

@ -10,10 +10,10 @@ Date and time handling for Rust.
```rust
// find out if the doomsday rule is correct!
use chrono::{MIN_YEAR, MAX_YEAR, Weekday, DateZ};
use chrono::{Weekday, DateZ, date};
use std::iter::range_inclusive;
for y in range_inclusive(MIN_YEAR, MAX_YEAR) {
for y in range_inclusive(date::MINZ.year(), date::MAXZ.year()) {
// even months
let d4 = DateZ::from_ymd(y, 4, 4);
let d6 = DateZ::from_ymd(y, 6, 6);

View File

@ -225,17 +225,19 @@ pub struct DateZ {
}
/// The minimum possible `DateZ`.
pub static MIN: DateZ = DateZ { ymdf: (MIN_YEAR << 13) | (1 << 4) | 0o07 /*FE*/ };
pub static MINZ: DateZ = DateZ { ymdf: (MIN_YEAR << 13) | (1 << 4) | 0o07 /*FE*/ };
/// The maximum possible `DateZ`.
pub static MAX: DateZ = DateZ { ymdf: (MAX_YEAR << 13) | (365 << 4) | 0o17 /*F*/ };
pub static MAXZ: DateZ = DateZ { ymdf: (MAX_YEAR << 13) | (365 << 4) | 0o17 /*F*/ };
// as it is hard to verify year flags in `MIN` and `MAX`, we use a separate run-time test.
#[test]
fn test_datez_bounds() {
let calculated_min = DateZ::from_ymd(MIN_YEAR, 1, 1);
let calculated_max = DateZ::from_ymd(MAX_YEAR, 12, 31);
assert!(MIN == calculated_min, "`MIN` should have a year flag {}", calculated_min.of().flags());
assert!(MAX == calculated_max, "`MAX` should have a year flag {}", calculated_max.of().flags());
assert!(MINZ == calculated_min,
"`MINZ` should have a year flag {}", calculated_min.of().flags());
assert!(MAXZ == calculated_max,
"`MAXZ` should have a year flag {}", calculated_max.of().flags());
}
impl DateZ {
@ -464,8 +466,8 @@ impl Datelike for DateZ {
}
impl num::Bounded for DateZ {
#[inline] fn min_value() -> DateZ { MIN }
#[inline] fn max_value() -> DateZ { MAX }
#[inline] fn min_value() -> DateZ { MINZ }
#[inline] fn max_value() -> DateZ { MAXZ }
}
impl Add<Duration,DateZ> for DateZ {

View File

@ -29,7 +29,7 @@ pub mod datetime;
fn test_readme_doomsday() {
use std::iter::range_inclusive;
for y in range_inclusive(date::MIN.year(), date::MAX.year()) {
for y in range_inclusive(date::MINZ.year(), date::MAXZ.year()) {
// even months
let d4 = DateZ::from_ymd(y, 4, 4);
let d6 = DateZ::from_ymd(y, 6, 6);