[][src]Struct chronoutil::rule::DateRule

pub struct DateRule<D: Datelike> { /* fields omitted */ }

DateRule is an iterator for yielding evenly spaced dates according to a given RelativeDuration. It avoids some of the pitfalls that naive usage of RelativeDuration can incur.

Implementations

impl<D> DateRule<D> where
    D: Datelike + Copy
[src]

pub fn new(start: D, freq: RelativeDuration) -> Self[src]

Creates a new DateRule from an initial date and relative duration.

pub fn secondly(from: D) -> Self[src]

Creates a DateRule yielding dates one second appart.

pub fn minutely(from: D) -> Self[src]

Creates a DateRule yielding dates one minute appart.

pub fn hourly(from: D) -> Self[src]

Creates a DateRule yielding dates one hour appart.

pub fn daily(from: D) -> Self[src]

Creates a DateRule yielding dates one day appart.

pub fn weekly(from: D) -> Self[src]

Creates a DateRule yielding dates one week appart.

pub fn monthly(from: D) -> Self[src]

Creates a DateRule yielding dates one month appart. Ambiguous month-ends are shifted backwards as necessary.

pub fn yearly(from: D) -> Self[src]

Creates a DateRule yielding dates one year appart. Ambiguous month-ends are shifted backwards as necessary.

pub fn with_count(&self, number: usize) -> Self[src]

Limits the DateRule to a given number of dates.

pub fn with_end(&self, end: D) -> Self[src]

Limits the DateRule to an extremal date (exclusive).

If using a RelativeDuration which shifts dates backwards, the end date should be before the current date.

WARNING: a forward-shifting duration with an end-date before the initial date will result in an iterator which does not terminate.

pub fn with_rolling_day(&self, rolling_day: u32) -> Result<Self, String>[src]

Ensure the DateRule yields new dates which are always fall on the given rolling day (modulo backwards shifting for month ends). Returns Err if the rolling day is not in the range 1-31.

For example:

let start = NaiveDate::from_ymd(2020, 2, 29);
let mut rule = DateRule::monthly(start).with_rolling_day(31).unwrap();

assert_eq!(rule.next().unwrap(), NaiveDate::from_ymd(2020, 2, 29));
assert_eq!(rule.next().unwrap(), NaiveDate::from_ymd(2020, 3, 31));
assert_eq!(rule.next().unwrap(), NaiveDate::from_ymd(2020, 4, 30));
assert_eq!(rule.next().unwrap(), NaiveDate::from_ymd(2020, 5, 31));
// etc.

It produces values equivalent to

rule.map(|d| with_day(d, rolling_day).unwrap())

Trait Implementations

impl<D: Clone + Datelike> Clone for DateRule<D>[src]

impl<D: Copy + Datelike> Copy for DateRule<D>[src]

impl<D: Debug + Datelike> Debug for DateRule<D>[src]

impl<D: Eq + Datelike> Eq for DateRule<D>[src]

impl Iterator for DateRule<NaiveDate>[src]

type Item = NaiveDate

The type of the elements being iterated over.

impl Iterator for DateRule<NaiveDateTime>[src]

type Item = NaiveDateTime

The type of the elements being iterated over.

impl<Tz> Iterator for DateRule<Date<Tz>> where
    Tz: TimeZone
[src]

type Item = Date<Tz>

The type of the elements being iterated over.

impl<Tz> Iterator for DateRule<DateTime<Tz>> where
    Tz: TimeZone
[src]

type Item = DateTime<Tz>

The type of the elements being iterated over.

impl<D: PartialEq + Datelike> PartialEq<DateRule<D>> for DateRule<D>[src]

impl<D: Datelike> StructuralEq for DateRule<D>[src]

impl<D: Datelike> StructuralPartialEq for DateRule<D>[src]

Auto Trait Implementations

impl<D> RefUnwindSafe for DateRule<D> where
    D: RefUnwindSafe
[src]

impl<D> Send for DateRule<D> where
    D: Send
[src]

impl<D> Sync for DateRule<D> where
    D: Sync
[src]

impl<D> Unpin for DateRule<D> where
    D: Unpin
[src]

impl<D> UnwindSafe for DateRule<D> where
    D: UnwindSafe
[src]

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<I> IntoIterator for I where
    I: Iterator
[src]

type Item = <I as Iterator>::Item

The type of the elements being iterated over.

type IntoIter = I

Which kind of iterator are we turning this into?

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.