summaryrefslogtreecommitdiff
path: root/src/rrule.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/rrule.rs')
-rw-r--r--src/rrule.rs32
1 files changed, 26 insertions, 6 deletions
diff --git a/src/rrule.rs b/src/rrule.rs
index 5083161..68f77ad 100644
--- a/src/rrule.rs
+++ b/src/rrule.rs
@@ -14,6 +14,7 @@ impl RRule {
Self { options }
}
+ /// Returns all the recurrences of the rrule
pub fn all(&mut self) -> Vec<DateTime<Tz>> {
let iter_args = IterArgs {
inc: true,
@@ -26,8 +27,11 @@ impl RRule {
let res = iter(&mut iter_res, &mut self.options);
res
}
-
- pub fn before(&mut self, dt: DateTime<Tz>, inc: bool) -> Vec<DateTime<Tz>> {
+
+ /// Returns the last recurrence before the given datetime instance.
+ /// The inc keyword defines what happens if dt is an recurrence.
+ /// With inc == true, if dt itself is an recurrence, it will be returned.
+ pub fn before(&mut self, dt: DateTime<Tz>, inc: bool) -> Option<DateTime<Tz>> {
let iter_args = IterArgs {
inc,
before: None,
@@ -36,10 +40,18 @@ impl RRule {
};
let mut iter_res = RRuleIterRes::new(QueryMethodTypes::Before, iter_args);
- iter(&mut iter_res, &mut self.options)
+ let recurrences = iter(&mut iter_res, &mut self.options);
+ if recurrences.is_empty() {
+ None
+ } else {
+ Some(recurrences[0])
+ }
}
- pub fn after(&mut self, dt: DateTime<Tz>, inc: bool) -> Vec<DateTime<Tz>> {
+ /// Returns the last recurrence after the given datetime instance.
+ /// The inc keyword defines what happens if dt is an recurrence.
+ /// With inc == true, if dt itself is an recurrence, it will be returned.
+ pub fn after(&mut self, dt: DateTime<Tz>, inc: bool) -> Option<DateTime<Tz>> {
let iter_args = IterArgs {
inc,
before: None,
@@ -47,10 +59,18 @@ impl RRule {
dt: Some(dt),
};
let mut iter_res = RRuleIterRes::new(QueryMethodTypes::After, iter_args);
-
- iter(&mut iter_res, &mut self.options)
+ let recurrences = iter(&mut iter_res, &mut self.options);
+ if recurrences.is_empty() {
+ None
+ } else {
+ Some(recurrences[0])
+ }
}
+ /// Returns all the recurrences of the rrule between after and before.
+ /// The inc keyword defines what happens if after and/or before are
+ /// themselves recurrences. With inc == true, they will be included in the
+ /// list, if they are found in the recurrence set.
pub fn between(
&mut self,
after: DateTime<Tz>,