Skip to content

Commit

Permalink
Doctests
Browse files Browse the repository at this point in the history
  • Loading branch information
oliver committed Jan 6, 2021
1 parent 7e82f80 commit af94854
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ For example, the following will yield one `NaiveDate` on the last day of each
month in 2025:

```rust
let start = NaiveDate::ymd(2025, 1, 31);
let start = NaiveDate::from_ymd(2025, 1, 31);
let rule = DateRule<NaiveDate>::monthly(start).with_count(12);
// 2025-1-31, 2025-2-28, 2025-3-31, 2025-4-30, ...
```
Expand Down Expand Up @@ -93,11 +93,11 @@ This leads us to an interesting point about the `RelativeDuration`: addition is
_associative_:

```rust
let d1 = NaiveDate::ymd(2020, 1, 31) + RelativeDuration::months(1) + RelativeDuration::months(1);
let d2 = NaiveDate::ymd(2020, 1, 31) + (RelativeDuration::months(1) + RelativeDuration::months(1));
let d1 = (NaiveDate::from_ymd(2020, 1, 31) + RelativeDuration::months(1)) + RelativeDuration::months(1);
let d2 = NaiveDate::from_ymd(2020, 1, 31) + (RelativeDuration::months(1) + RelativeDuration::months(1));

assert_eq!(d1, NaiveDate::ymd(2020, 3, 29));
assert_eq!(d2, NaiveDate::ymd(2020, 3, 31));
assert_eq!(d1, NaiveDate::from_ymd(2020, 3, 29));
assert_eq!(d2, NaiveDate::from_ymd(2020, 3, 31));
```

If you want a series of shifted dates, we advise using the `DateRule`, which takes
Expand Down
17 changes: 11 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@
//! month in 2025:
//!
//! ```rust
//! let start = NaiveDate::ymd(2025, 1, 31);
//! let rule = DateRule<NaiveDate>::monthly(start).with_count(12);
//! # use chrono::NaiveDate;
//! # use chronoutil::DateRule;
//! let start = NaiveDate::from_ymd(2025, 1, 31);
//! let rule = DateRule::monthly(start).with_count(12);
//! // 2025-1-31, 2025-2-28, 2025-3-31, 2025-4-30, ...
//! ```
//!
Expand Down Expand Up @@ -72,11 +74,14 @@
//! _associative_:
//!
//! ```rust
//! let d1 = NaiveDate::ymd(2020, 1, 31) + RelativeDuration::months(1) + RelativeDuration::months(1);
//! let d2 = NaiveDate::ymd(2020, 1, 31) + (RelativeDuration::months(1) + RelativeDuration::months(1));
//! # use chrono::NaiveDate;
//! # use chronoutil::RelativeDuration;
//!
//! assert_eq!(d1, NaiveDate::ymd(2020, 3, 29));
//! assert_eq!(d2, NaiveDate::ymd(2020, 3, 31));
//! let d1 = (NaiveDate::from_ymd(2020, 1, 31) + RelativeDuration::months(1)) + RelativeDuration::months(1);
//! let d2 = NaiveDate::from_ymd(2020, 1, 31) + (RelativeDuration::months(1) + RelativeDuration::months(1));
//!
//! assert_eq!(d1, NaiveDate::from_ymd(2020, 3, 29));
//! assert_eq!(d2, NaiveDate::from_ymd(2020, 3, 31));
//! ```
//!
//! If you want a series of shifted dates, we advise using the `DateRule`, which takes
Expand Down

0 comments on commit af94854

Please sign in to comment.