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:
parent
4dbd00dca2
commit
9300f2481c
|
@ -10,10 +10,10 @@ Date and time handling for Rust.
|
||||||
|
|
||||||
```rust
|
```rust
|
||||||
// find out if the doomsday rule is correct!
|
// 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;
|
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
|
// even months
|
||||||
let d4 = DateZ::from_ymd(y, 4, 4);
|
let d4 = DateZ::from_ymd(y, 4, 4);
|
||||||
let d6 = DateZ::from_ymd(y, 6, 6);
|
let d6 = DateZ::from_ymd(y, 6, 6);
|
||||||
|
|
14
src/date.rs
14
src/date.rs
|
@ -225,17 +225,19 @@ pub struct DateZ {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The minimum possible `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`.
|
/// 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.
|
// as it is hard to verify year flags in `MIN` and `MAX`, we use a separate run-time test.
|
||||||
#[test]
|
#[test]
|
||||||
fn test_datez_bounds() {
|
fn test_datez_bounds() {
|
||||||
let calculated_min = DateZ::from_ymd(MIN_YEAR, 1, 1);
|
let calculated_min = DateZ::from_ymd(MIN_YEAR, 1, 1);
|
||||||
let calculated_max = DateZ::from_ymd(MAX_YEAR, 12, 31);
|
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!(MINZ == calculated_min,
|
||||||
assert!(MAX == calculated_max, "`MAX` should have a year flag {}", calculated_max.of().flags());
|
"`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 {
|
impl DateZ {
|
||||||
|
@ -464,8 +466,8 @@ impl Datelike for DateZ {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl num::Bounded for DateZ {
|
impl num::Bounded for DateZ {
|
||||||
#[inline] fn min_value() -> DateZ { MIN }
|
#[inline] fn min_value() -> DateZ { MINZ }
|
||||||
#[inline] fn max_value() -> DateZ { MAX }
|
#[inline] fn max_value() -> DateZ { MAXZ }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Add<Duration,DateZ> for DateZ {
|
impl Add<Duration,DateZ> for DateZ {
|
||||||
|
|
|
@ -29,7 +29,7 @@ pub mod datetime;
|
||||||
fn test_readme_doomsday() {
|
fn test_readme_doomsday() {
|
||||||
use std::iter::range_inclusive;
|
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
|
// even months
|
||||||
let d4 = DateZ::from_ymd(y, 4, 4);
|
let d4 = DateZ::from_ymd(y, 4, 4);
|
||||||
let d6 = DateZ::from_ymd(y, 6, 6);
|
let d6 = DateZ::from_ymd(y, 6, 6);
|
||||||
|
|
Loading…
Reference in New Issue