aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRuben Pollan2018-08-28 19:27:01 +0200
committerRuben Pollan2018-08-28 19:27:01 +0200
commit92b1ebe43e90cc9c851ce87e1b4e597b5eb3e3ef (patch)
tree2ce29d006c2921e4fd58e86dd8e6bc86feb57f99
parent50e9a4421c7a27bcf01d7adab8d20b7df18f534c (diff)
Add support for count on periodic events
-rw-r--r--src/main.rs4
-rw-r--r--src/periodic.rs10
2 files changed, 11 insertions, 3 deletions
diff --git a/src/main.rs b/src/main.rs
index 66e1df1..67eb0fc 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -25,5 +25,7 @@ fn main() {
let now = Date::now();
let events = calendar.get(&now, &(now + Duration::weeks(10)));
- println!("{:?}", events);
+ for e in events {
+ println!("{}", e);
+ }
}
diff --git a/src/periodic.rs b/src/periodic.rs
index f6cd2d7..af9810c 100644
--- a/src/periodic.rs
+++ b/src/periodic.rs
@@ -12,8 +12,8 @@ pub struct Periodic {
pub event: Event,
pub freq: Freq,
pub interval: i64,
+ pub count: i64,
pub until: Date,
- // TODO: count, ...
}
#[derive(Debug)]
@@ -34,6 +34,7 @@ impl Periodic {
freq: Freq::Secondly,
interval: 1,
until: Date::empty(),
+ count: 0,
}
}
@@ -41,6 +42,7 @@ impl Periodic {
match param {
"FREQ" => self.freq = value.parse()?,
"INTERVAL" => self.interval = value.parse()?,
+ "COUNT" => self.count = value.parse()?,
"UNTIL" => self.until = Date::parse(&value, "")?,
_ => (),
}
@@ -51,8 +53,11 @@ impl Periodic {
let mut start = self.event.start;
let mut end = self.event.end_date();
let mut events = Vec::new();
+ let mut count = 0;
while start <= *last {
- if !self.until.is_empty() && start <= self.until {
+ if (!self.until.is_empty() && start <= self.until) ||
+ (count != 0 && count >= self.count)
+ {
break;
}
@@ -61,6 +66,7 @@ impl Periodic {
e.start = start;
e.end = End::Date(end);
events.push(e);
+ count += count;
}
start = start + self.freq.duration(self.interval);
end = end + self.freq.duration(self.interval);