aboutsummaryrefslogtreecommitdiff
path: root/src/date.rs
diff options
context:
space:
mode:
authorRuben Pollan2018-08-28 19:55:13 +0200
committerRuben Pollan2018-08-28 19:55:13 +0200
commitd7fffd15cb148bab2fa9a9e58d3f323231aac5e3 (patch)
treebfcc395c7468c1ee98dad9af350c39308c8f864c /src/date.rs
parent92b1ebe43e90cc9c851ce87e1b4e597b5eb3e3ef (diff)
Add support for month and year frequency
Diffstat (limited to '')
-rw-r--r--src/date.rs30
1 files changed, 29 insertions, 1 deletions
diff --git a/src/date.rs b/src/date.rs
index b703766..f77b5d5 100644
--- a/src/date.rs
+++ b/src/date.rs
@@ -4,7 +4,7 @@ use std::ops::Add;
use errors::EventError;
use chrono;
-use chrono::{TimeZone, Duration};
+use chrono::{TimeZone, Duration, Datelike};
use chrono::offset::Utc;
use chrono_tz::{Tz, UTC};
@@ -64,6 +64,34 @@ impl Date {
};
Ok(date)
}
+
+ pub fn month(&self) -> u32 {
+ match *self {
+ Date::Time(t) => t.month(),
+ Date::AllDay(d) => d.month(),
+ }
+ }
+
+ pub fn with_month(&self, month: u32) -> Option<Date> {
+ Some(match *self {
+ Date::Time(t) => Date::Time(t.with_month(month)?),
+ Date::AllDay(d) => Date::AllDay(d.with_month(month)?),
+ })
+ }
+
+ pub fn year(&self) -> i32 {
+ match *self {
+ Date::Time(t) => t.year(),
+ Date::AllDay(d) => d.year(),
+ }
+ }
+
+ pub fn with_year(&self, year: i32) -> Option<Date> {
+ Some(match *self {
+ Date::Time(t) => Date::Time(t.with_year(year)?),
+ Date::AllDay(d) => Date::AllDay(d.with_year(year)?),
+ })
+ }
}
impl Ord for Date {