Skip to content

Commit b79f6b3

Browse files
committed
major API surgeries.
- added a new example. - reexported all public APIs in the crate root. - made all constructors fail on the invalid arguments by default; `*_opt()` variants have been added for the original behavior. - same for `DateZ::{succ,pred}`. - fixed a missing overflow check from `TimeZ::from_hms_{milli,micro}`.
1 parent dce4ec8 commit b79f6b3

File tree

5 files changed

+335
-141
lines changed

5 files changed

+335
-141
lines changed

README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,34 @@ Rust-chrono
88

99
Date and time handling for Rust.
1010

11+
```rust
12+
// find out if the doomsday rule is correct!
13+
use chrono::{MIN_YEAR, MAX_YEAR, Weekday, DateZ};
14+
use std::iter::range_inclusive;
15+
16+
for y in range_inclusive(MIN_YEAR, MAX_YEAR) {
17+
// even months
18+
let d4 = DateZ::from_ymd(y, 4, 4);
19+
let d6 = DateZ::from_ymd(y, 6, 6);
20+
let d8 = DateZ::from_ymd(y, 8, 8);
21+
let d10 = DateZ::from_ymd(y, 10, 10);
22+
let d12 = DateZ::from_ymd(y, 12, 12);
23+
24+
// nine to five, seven-eleven
25+
let d59 = DateZ::from_ymd(y, 5, 9);
26+
let d95 = DateZ::from_ymd(y, 9, 5);
27+
let d711 = DateZ::from_ymd(y, 7, 11);
28+
let d117 = DateZ::from_ymd(y, 11, 7);
29+
30+
// "March 0"
31+
let d30 = DateZ::from_ymd(y, 3, 1).pred();
32+
33+
let weekday = d30.weekday();
34+
let other_dates = [d4, d6, d8, d10, d12, d59, d95, d711, d117];
35+
assert!(other_dates.iter().all(|d| d.weekday() == weekday));
36+
}
37+
```
38+
1139
Design Goals
1240
------------
1341

0 commit comments

Comments
 (0)