aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/date.rs24
1 files changed, 23 insertions, 1 deletions
diff --git a/src/date.rs b/src/date.rs
index dced057..b703766 100644
--- a/src/date.rs
+++ b/src/date.rs
@@ -1,9 +1,11 @@
use std::cmp::{Ordering, Ord, PartialEq, PartialOrd};
+use std::ops::Add;
use errors::EventError;
use chrono;
-use chrono::TimeZone;
+use chrono::{TimeZone, Duration};
+use chrono::offset::Utc;
use chrono_tz::{Tz, UTC};
@@ -19,6 +21,15 @@ impl Date {
Date::Time(UTC.timestamp(0, 0))
}
+
+ pub fn now() -> 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 {
@@ -86,6 +97,17 @@ impl PartialEq for Date {
}
}
+impl Add<Duration> for Date {
+ type Output = Date;
+
+ fn add(self, other: Duration) -> Date {
+ match self {
+ Date::Time(d) => Date::Time(d + other),
+ Date::AllDay(d) => Date::AllDay(d + other),
+ }
+ }
+}
+
fn cmp_date_time<T: TimeZone>(date: &chrono::Date<T>, time: &chrono::DateTime<T>) -> Ordering {
let d2 = time.date();
if date.eq(&d2) {