pub enum Frequency {
    Secondly {
        interval: i32,
    },
    Minutely {
        interval: i32,
    },
    Hourly {
        interval: i32,
    },
    Daily {
        interval: i32,
        by_time: Vec<Time>,
    },
    Weekly {
        interval: i32,
        by_day: Vec<Weekday>,
    },
    Monthly {
        interval: i32,
        by_month_day: Vec<i32>,
        nth_weekdays: Vec<NthWeekday>,
    },
    Yearly {
        interval: i32,
        by_monthly_date: Option<MonthlyDate>,
    },
}
Expand description

Representation of the frequency of a recurrence. E.g. Once a day, Twice a week, etc.

Examples:

use rrules::{Frequency};

let once_a_day = Frequency::Daily {interval: 1, by_time: vec![]};
assert_eq!(once_a_day.to_string(), "FREQ=DAILY;INTERVAL=1");

let three_times_a_month = Frequency::Monthly {
    interval: 1,
    by_month_day: vec![1, 10, 20],
    nth_weekdays: vec![]
};
assert_eq!(three_times_a_month.to_string(), "FREQ=MONTHLY;INTERVAL=1;BYMONTHDAY=1,10,20");

Variants§

§

Secondly

Fields

§interval: i32
§

Minutely

Fields

§interval: i32
§

Hourly

Fields

§interval: i32
§

Daily

Fields

§interval: i32
§by_time: Vec<Time>
§

Weekly

Fields

§interval: i32
§by_day: Vec<Weekday>
§

Monthly

Fields

§interval: i32
§by_month_day: Vec<i32>
§nth_weekdays: Vec<NthWeekday>
§

Yearly

Fields

§interval: i32
§by_monthly_date: Option<MonthlyDate>

Implementations§

source§

impl Frequency

source

pub fn is_valid(&self) -> Result<(), InvalidFrequency>

Verifies if the frequency is valid.

source

pub fn next_event(&self, current_date: &DateTime<Utc>) -> Option<DateTime<Utc>>

Returns the next event date for the current frequencies config given the current date. Returns None if there is no next event. E.g. If the frequency is once a day and the current date is 2020-01-01, the next event date will be 2020-01-02.

source

pub fn contains(&self, date: &DateTime<Utc>) -> bool

Verifies if the specified date is a valid event date for the current frequency. E.g. If the frequency is once a day and the date is 2023-01-01, the method will return true. If the frequency is Once a week on Monday and the date is 2023-01-01, the method will return false because the date is not a Monday.

use std::str::FromStr;
use rrules::Frequency;
use chrono::{Utc, DateTime, Duration, Weekday};

let once_a_day = Frequency::Daily {interval: 1,by_time: vec![]};
let sunday = DateTime::<Utc>::from_str("2023-01-01T00:00:00Z").unwrap();
assert!(once_a_day.contains(&sunday));

let every_monday = Frequency::Weekly {interval: 1, by_day: vec![Weekday::Mon]};
assert!(!every_monday.contains(&sunday));

Trait Implementations§

source§

impl Clone for Frequency

source§

fn clone(&self) -> Frequency

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Frequency

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Display for Frequency

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl FromStr for Frequency

§

type Err = InvalidFrequency

The associated error which can be returned from parsing.
source§

fn from_str(s: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for Twhere T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

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

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.