diff options
| author | Nathan Perry <np@nathanperry.dev> | 2020-09-26 16:02:31 -0400 |
|---|---|---|
| committer | Nathan Perry <np@nathanperry.dev> | 2020-09-26 16:02:31 -0400 |
| commit | 23ce35dffe6b8b1fc6e5fd418db6a63922b20c86 (patch) | |
| tree | ea814e4180030db5ad3571e4d2dfe40d9cab47a0 | |
| parent | c12afcf2f06d2d477348952692bf4662ff9ce779 (diff) | |
switch to datetime
| -rw-r--r-- | src/commands/today/france.rs | 2 | ||||
| -rw-r--r-- | src/commands/today/halloween.rs | 2 | ||||
| -rw-r--r-- | src/commands/today/mod.rs | 23 | ||||
| -rw-r--r-- | src/commands/today/nov_5.rs | 2 | ||||
| -rw-r--r-- | src/commands/today/prelude.rs | 2 | ||||
| -rw-r--r-- | src/commands/today/sept_21.rs | 4 | ||||
| -rw-r--r-- | src/commands/today/shrek.rs | 2 | ||||
| -rw-r--r-- | src/commands/today/tomorrow.rs | 2 | ||||
| -rw-r--r-- | src/commands/today/ussr.rs | 2 | ||||
| -rw-r--r-- | src/commands/today/wednesday.rs | 2 |
10 files changed, 26 insertions, 17 deletions
diff --git a/src/commands/today/france.rs b/src/commands/today/france.rs index 28c7b96..be589cb 100644 --- a/src/commands/today/france.rs +++ b/src/commands/today/france.rs @@ -1,6 +1,6 @@ use super::prelude::*; -pub fn france(date: chrono::NaiveDate) -> TodayIter { +pub fn france(date: chrono::NaiveDateTime) -> TodayIter { let ok = match month_day(date) { // bastille day (7, 14) => true, diff --git a/src/commands/today/halloween.rs b/src/commands/today/halloween.rs index 847da8e..3fb1c18 100644 --- a/src/commands/today/halloween.rs +++ b/src/commands/today/halloween.rs @@ -9,7 +9,7 @@ lazy_static! { ]; } -pub fn halloween(date: chrono::NaiveDate) -> TodayIter { +pub fn halloween(date: chrono::NaiveDateTime) -> TodayIter { if (10, 31) != month_day(date) { return Box::new(empty()); } diff --git a/src/commands/today/mod.rs b/src/commands/today/mod.rs index 3f5373c..50cee99 100644 --- a/src/commands/today/mod.rs +++ b/src/commands/today/mod.rs @@ -64,7 +64,7 @@ impl TodayArgs { lazy_static! { - static ref ALL: Vec<fn(chrono::NaiveDate) -> TodayIter> = vec! [ + static ref ALL: Vec<fn(chrono::NaiveDateTime) -> TodayIter> = vec! [ sept_21::sept_21, nov_5::nov_5, @@ -84,16 +84,25 @@ lazy_static! { pub fn today(ctx: &mut Context, msg: &Message, _args: Args) -> Result<()> { let today = { #[allow(unused_mut)] - let mut result = chrono::Local::today().naive_local(); + let mut result = chrono::Local::now().naive_local(); #[cfg(debug_assertions)] { - match _args.parse::<chrono::NaiveDate>() { - Ok(date) => { - log::debug!("overriding with date: {}", date); - result = date; + let dt = _args.parse::<chrono::NaiveDateTime>() + .or_else(|_| { + _args.parse::<chrono::NaiveDate>() + .map(|date| { + let time = chrono::NaiveTime::from_hms(12, 0, 0); + date.and_time(time) + }) + }); + + match dt { + Ok(dt) => { + log::debug!("overriding with datetime: {}", dt); + result = dt; }, Err(e) => { - log::debug!("parsing date: {:?}", e); + log::debug!("parsing datetime: {:?}", e); } }; } diff --git a/src/commands/today/nov_5.rs b/src/commands/today/nov_5.rs index 30d4f79..b4eafc9 100644 --- a/src/commands/today/nov_5.rs +++ b/src/commands/today/nov_5.rs @@ -1,6 +1,6 @@ use super::prelude::*; -pub fn nov_5(date: chrono::NaiveDate) -> TodayIter { +pub fn nov_5(date: chrono::NaiveDateTime) -> TodayIter { if (11, 5) != month_day(date) { return Box::new(empty()); } diff --git a/src/commands/today/prelude.rs b/src/commands/today/prelude.rs index d0570fd..d5f470d 100644 --- a/src/commands/today/prelude.rs +++ b/src/commands/today/prelude.rs @@ -17,7 +17,7 @@ pub use super::{ #[inline] -pub fn month_day(date: chrono::NaiveDate) -> (u32, u32) { +pub fn month_day(date: chrono::NaiveDateTime) -> (u32, u32) { (date.month(), date.day()) } diff --git a/src/commands/today/sept_21.rs b/src/commands/today/sept_21.rs index 06689e8..f01e7bd 100644 --- a/src/commands/today/sept_21.rs +++ b/src/commands/today/sept_21.rs @@ -32,8 +32,8 @@ lazy_static! { ]; } -pub fn sept_21(date: chrono::NaiveDate) -> TodayIter { - if (9, 21) != (date.month(), date.day()) { +pub fn sept_21(date: chrono::NaiveDateTime) -> TodayIter { + if (9, 21) != month_day(date) { return Box::new(empty()); } diff --git a/src/commands/today/shrek.rs b/src/commands/today/shrek.rs index 0f16337..b2f24a1 100644 --- a/src/commands/today/shrek.rs +++ b/src/commands/today/shrek.rs @@ -1,6 +1,6 @@ use super::prelude::*; -pub fn shrek(date: chrono::NaiveDate) -> TodayIter { +pub fn shrek(date: chrono::NaiveDateTime) -> TodayIter { if month_day(date) != (4, 22) { return Box::new(empty()); } diff --git a/src/commands/today/tomorrow.rs b/src/commands/today/tomorrow.rs index eb19250..ad5c37d 100644 --- a/src/commands/today/tomorrow.rs +++ b/src/commands/today/tomorrow.rs @@ -1,6 +1,6 @@ use super::prelude::*; -pub fn tomorrow(_date: chrono::NaiveDate) -> TodayIter { +pub fn tomorrow(_date: chrono::NaiveDateTime) -> TodayIter { Box::new( once( TodayArgs { diff --git a/src/commands/today/ussr.rs b/src/commands/today/ussr.rs index 7085d82..cc3671e 100644 --- a/src/commands/today/ussr.rs +++ b/src/commands/today/ussr.rs @@ -1,6 +1,6 @@ use super::prelude::*; -pub fn ussr(date: chrono::NaiveDate) -> TodayIter { +pub fn ussr(date: chrono::NaiveDateTime) -> TodayIter { let ok = match month_day(date) { // red army day (2, 23) => true, diff --git a/src/commands/today/wednesday.rs b/src/commands/today/wednesday.rs index 8fec707..0748a0b 100644 --- a/src/commands/today/wednesday.rs +++ b/src/commands/today/wednesday.rs @@ -1,6 +1,6 @@ use super::prelude::*; -pub fn wednesday(date: chrono::NaiveDate) -> TodayIter { +pub fn wednesday(date: chrono::NaiveDateTime) -> TodayIter { if date.weekday() != chrono::Weekday::Wed { return Box::new(empty()); } |
