Enum rrules::frequencies::models::Frequency
source · 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§
Implementations§
source§impl Frequency
impl Frequency
sourcepub fn is_valid(&self) -> Result<(), InvalidFrequency>
pub fn is_valid(&self) -> Result<(), InvalidFrequency>
Verifies if the frequency is valid.
sourcepub fn next_event(&self, current_date: &DateTime<Utc>) -> Option<DateTime<Utc>>
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.
sourcepub fn contains(&self, date: &DateTime<Utc>) -> bool
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§
Auto Trait Implementations§
impl RefUnwindSafe for Frequency
impl Send for Frequency
impl Sync for Frequency
impl Unpin for Frequency
impl UnwindSafe for Frequency
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more