aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRuben Pollan2018-08-28 20:33:43 +0200
committerRuben Pollan2018-08-28 20:33:43 +0200
commit7e7dfc3d76b810f22f68f4e5334c9d89dd7d85cc (patch)
treeaf5832baf63c90c0a74c0b96a6fef776323096ca /src
parentd7fffd15cb148bab2fa9a9e58d3f323231aac5e3 (diff)
Let's use Option the rustic way
Diffstat (limited to 'src')
-rw-r--r--src/date.rs6
-rw-r--r--src/event.rs4
-rw-r--r--src/periodic.rs16
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;
}