aboutsummaryrefslogtreecommitdiff
path: root/src/periodic.rs
diff options
context:
space:
mode:
authorRuben Pollan2018-08-25 19:09:30 +0200
committerRuben Pollan2018-08-25 19:09:30 +0200
commitb80fb44d83f9460f9d1ab4c831e7c6a9baf44c16 (patch)
treeee4d68982588bd7b80b98816bc45ff9285132d7b /src/periodic.rs
parent53034be0511b00b73cd7d3780083996022e4adbb (diff)
Basic periodic events support
Diffstat (limited to 'src/periodic.rs')
-rw-r--r--src/periodic.rs64
1 files changed, 64 insertions, 0 deletions
diff --git a/src/periodic.rs b/src/periodic.rs
new file mode 100644
index 0000000..0fa06ef
--- /dev/null
+++ b/src/periodic.rs
@@ -0,0 +1,64 @@
+use std::fmt;
+use std::str::FromStr;
+
+use event::Event;
+use errors::EventError;
+
+#[derive(Debug)]
+pub struct Periodic {
+ pub event: Event,
+ pub freq: Freq,
+ // TODO: until, count, interval, ...
+}
+
+#[derive(Debug)]
+pub enum Freq {
+ Secondly,
+ Minutely,
+ Hourly,
+ Daily,
+ Weekly,
+ Monthly,
+ Yearly,
+}
+
+impl Periodic {
+ pub fn new() -> Self {
+ Self {
+ event: Event::new(),
+ freq: Freq::Secondly,
+ }
+ }
+
+ pub fn set_param(&mut self, param: &str, value: &str) -> Result<(), EventError> {
+ match param {
+ "FREQ" => self.freq = value.parse()?,
+ _ => (),
+ }
+ Ok(())
+ }
+}
+
+impl fmt::Display for Periodic {
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ write!(f, "{:?}: {}", self.freq, self.event)?;
+ Ok(())
+ }
+}
+
+impl FromStr for Freq {
+ type Err = EventError;
+
+ fn from_str(s: &str) -> Result<Self, Self::Err> {
+ match s {
+ "SECONDLY" => Ok(Freq::Secondly),
+ "MINUTELY" => Ok(Freq::Minutely),
+ "HOURLY" => Ok(Freq::Hourly),
+ "DAILY" => Ok(Freq::Daily),
+ "WEEKLY" => Ok(Freq::Weekly),
+ "MONTHLY" => Ok(Freq::Monthly),
+ "YEARLY" => Ok(Freq::Yearly),
+ _ => Err(EventError::FreqError),
+ }
+ }
+}