diff options
author | Ruben Pollan | 2020-05-19 11:29:25 +0200 |
---|---|---|
committer | Ruben Pollan | 2020-05-19 11:29:25 +0200 |
commit | 098ac045545d4149b0062bbb365bf7467eb2bff3 (patch) | |
tree | 7f12ea9a368ee36ce1b0ebfa4eff4caf53ffde6b /src/date.rs | |
parent | 365e8d37f1d97bc2f0f062f4594fbae1a90be93a (diff) |
Add support for ical's BYDAY recursion rule
Diffstat (limited to '')
-rw-r--r-- | src/date.rs | 32 |
1 files changed, 30 insertions, 2 deletions
diff --git a/src/date.rs b/src/date.rs index ab1c2c8..98e052a 100644 --- a/src/date.rs +++ b/src/date.rs @@ -1,10 +1,10 @@ use std::cmp::{Ordering, Ord}; -use std::ops::Add; +use std::ops::{Add, Sub}; use errors::EventError; use chrono; -use chrono::{TimeZone, Duration, Datelike, Local}; +use chrono::{TimeZone, Duration, Datelike, Local, Weekday}; use chrono::offset::Utc; use chrono_tz::{Tz, UTC}; @@ -79,6 +79,13 @@ impl Date { } } + pub fn weekday(&self) -> Weekday { + match *self { + Date::Time(t) => t.weekday(), + Date::AllDay(d) => d.weekday(), + } + } + pub fn month(&self) -> u32 { match *self { Date::Time(t) => t.month(), @@ -144,6 +151,27 @@ impl Add<Duration> for Date { } } +impl Sub<Date> for Date { + type Output = Duration; + + fn sub(self, other: Self) -> Duration { + match self { + Date::Time(t1) => { + match other { + Date::Time(t2) => t1 - t2, + Date::AllDay(d) => t1.date() - d, + } + } + Date::AllDay(d1) => { + match other { + Date::Time(t) => d1 - t.date(), + Date::AllDay(d2) => d1 - d2, + } + } + } + } +} + fn cmp_date_time<T: TimeZone>(date: &chrono::Date<T>, time: &chrono::DateTime<T>) -> Ordering { let d2 = time.date(); if date.eq(&d2) { |