summaryrefslogtreecommitdiff
path: root/src/lib.rs
diff options
context:
space:
mode:
authordfhoughton <dfhoughton@gmail.com>2018-12-28 16:41:03 -0500
committerdfhoughton <dfhoughton@gmail.com>2018-12-28 16:41:03 -0500
commit3201de663d1922846181cb252732c2de81aee393 (patch)
tree0ed7d107612737243f959f7547a7f3dde1d4b220 /src/lib.rs
parent4641db61c453f7198b24545f72c7d3e068f3f158 (diff)
downloadtwo-timer-3201de663d1922846181cb252732c2de81aee393.zip
handle relative months
Diffstat (limited to 'src/lib.rs')
-rw-r--r--src/lib.rs53
1 files changed, 24 insertions, 29 deletions
diff --git a/src/lib.rs b/src/lib.rs
index ad962e6..a3d0719 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -523,32 +523,6 @@ fn handle_specific_time(
} else {
Ok((last_moment(), last_moment()))
};
- // FIXME
- // if let Some(t) = moment.name("time") {
- // let (hour, minute, second) = time(t);
- // let period = if second.is_some() {
- // Period::Second
- // } else if minute.is_some() {
- // Period::Minute
- // } else {
- // Period::Hour
- // };
- // let mut t = other_time
- // .with_hour(hour)
- // .unwrap()
- // .with_minute(minute.unwrap_or(0))
- // .unwrap()
- // .with_second(second.unwrap_or(0))
- // .unwrap();
- // if before && t > *other_time {
- // t = t - Duration::days(1);
- // } else if !before && t < *other_time {
- // t = t + Duration::days(1);
- // }
- // return Ok(moment_to_period(t, &period, config));
- // } else {
- // unreachable!();
- // }
}
fn handle_one_time(
@@ -605,7 +579,7 @@ fn relative_moment(
if delta <= 0 {
delta += 7;
}
- let mut d = config.now.date() - Duration::days(delta);
+ let mut d = other_time.date() - Duration::days(delta);
if !before {
d = d + Duration::days(7);
}
@@ -637,8 +611,29 @@ fn relative_moment(
}
return moment_to_period(t, &period, config);
}
- if let Some(day) = m.name("named_period") {
- unimplemented!();
+ if let Some(month) = m.name("a_month") {
+ let month = a_month(month);
+ let year = if before {
+ if month > other_time.month() {
+ other_time.year() - 1
+ } else {
+ other_time.year()
+ }
+ } else {
+ if month < other_time.month() {
+ other_time.year() + 1
+ } else {
+ other_time.year()
+ }
+ };
+ let d = Utc.ymd(year, month, 1).and_hms(0, 0, 0);
+ let (d1, d2) = moment_to_period(d, &Period::Month, config);
+ if before && d1 >= *other_time {
+ return moment_to_period(d1.with_year(d1.year() - 1).unwrap(), &Period::Month, config);
+ } else if !before && d2 <= *other_time {
+ return moment_to_period(d1.with_year(d1.year() + 1).unwrap(), &Period::Month, config);
+ }
+ return (d1, d2);
}
unreachable!()
}