aboutsummaryrefslogtreecommitdiff
path: root/src/event.rs
diff options
context:
space:
mode:
authorRuben Pollan2018-08-28 16:48:59 +0200
committerRuben Pollan2018-08-28 16:48:59 +0200
commit6263be67208f68a8c8ce1a8a18fc9921df53048e (patch)
tree47da1c49686d16d06ae77743a50981aad7746dce /src/event.rs
parent5eb5bb17c0f7e93aacc340ce9a28ee352cc91c59 (diff)
Get a range of dates
Diffstat (limited to 'src/event.rs')
-rw-r--r--src/event.rs27
1 files changed, 24 insertions, 3 deletions
diff --git a/src/event.rs b/src/event.rs
index 904b718..b54c422 100644
--- a/src/event.rs
+++ b/src/event.rs
@@ -1,6 +1,8 @@
use std::fmt;
use std::str::FromStr;
+use chrono::Duration;
+
use date::Date;
use errors::EventError;
@@ -8,7 +10,7 @@ use errors::EventError;
#[derive(Debug, Clone)]
pub struct Event {
pub start: Date,
- pub end: Date,
+ pub end: End,
pub summary: String,
pub location: String,
pub description: String,
@@ -22,6 +24,12 @@ pub enum Status {
Canceled,
}
+#[derive(Debug, Copy, Clone)]
+pub enum End {
+ Date(Date),
+ Duration(Duration),
+}
+
impl Event {
pub fn new() -> Event {
@@ -31,14 +39,27 @@ impl Event {
description: "".to_string(),
status: Status::Confirmed,
start: Date::empty(),
- end: Date::empty(),
+ end: End::Date(Date::empty()),
};
}
+
+ pub fn end_date(&self) -> Date {
+ match self.end {
+ End::Date(date) => date,
+ End::Duration(duration) => self.start + duration,
+ }
+ }
}
impl fmt::Display for Event {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
- write!(f, "{:?}: {}", self.start, self.summary)?;
+ write!(
+ f,
+ "{:?}-{:?}: {}",
+ self.start,
+ self.end_date(),
+ self.summary
+ )?;
if !self.location.is_empty() {
write!(f, " ({})", self.location)?;
}