diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/date.rs | 6 | ||||
-rw-r--r-- | src/event.rs | 4 | ||||
-rw-r--r-- | src/periodic.rs | 16 |
3 files changed, 11 insertions, 15 deletions
diff --git a/src/date.rs b/src/date.rs index f77b5d5..c329ac3 100644 --- a/src/date.rs +++ b/src/date.rs @@ -17,7 +17,7 @@ pub enum Date { impl Date { - pub fn empty() -> Date { + pub fn new() -> Date { Date::Time(UTC.timestamp(0, 0)) } @@ -26,10 +26,6 @@ impl Date { Date::Time(UTC.from_utc_datetime(&Utc::now().naive_utc())) } - pub fn is_empty(&self) -> bool { - *self == Date::empty() - } - pub fn parse(date_str: &str, time_zone: &str) -> Result<Self, EventError> { let absolute_time = date_str.chars().rev().next().unwrap() == 'Z'; let tz: Tz = if absolute_time { diff --git a/src/event.rs b/src/event.rs index d086295..db32b22 100644 --- a/src/event.rs +++ b/src/event.rs @@ -38,8 +38,8 @@ impl Event { location: "".to_string(), description: "".to_string(), status: Status::Confirmed, - start: Date::empty(), - end: End::Date(Date::empty()), + start: Date::new(), + end: End::Date(Date::new()), }; } diff --git a/src/periodic.rs b/src/periodic.rs index b4bf7bf..0c52a9b 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, + pub count: Option<i64>, + pub until: Option<Date>, } #[derive(Debug)] @@ -33,8 +33,8 @@ impl Periodic { event: Event::new(), freq: Freq::Secondly, interval: 1, - until: Date::empty(), - count: 0, + count: None, + until: None, } } @@ -42,8 +42,8 @@ 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, "")?, + "COUNT" => self.count = Some(value.parse()?), + "UNTIL" => self.until = Some(Date::parse(&value, "")?), _ => (), } Ok(()) @@ -55,8 +55,8 @@ impl Periodic { let mut events = Vec::new(); let mut count = 0; while start <= *last { - if (!self.until.is_empty() && start <= self.until) || - (count != 0 && count >= self.count) + if (self.until.is_some() && start <= self.until.unwrap()) || + (self.count.is_some() && count >= self.count.unwrap()) { break; } |