aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNathan Perry <np@nathanperry.dev>2020-09-26 16:25:43 -0400
committerNathan Perry <np@nathanperry.dev>2020-09-26 16:25:43 -0400
commitdabb00ad4dda679e37dde1827f2b135c9183310c (patch)
tree77cf107ba581c0de55e3a1c0f353989f89036801
parent1b01a8a8c86de0e5d958ae5a62c9b7e98ac7d5e3 (diff)
pianoman: support 9am or 9pm
-rw-r--r--src/commands/today/pianoman.rs23
1 files changed, 13 insertions, 10 deletions
diff --git a/src/commands/today/pianoman.rs b/src/commands/today/pianoman.rs
index 5cc7382..fa3ac7e 100644
--- a/src/commands/today/pianoman.rs
+++ b/src/commands/today/pianoman.rs
@@ -1,7 +1,8 @@
use super::prelude::*;
lazy_static! {
- static ref TARGET_TIME: chrono::NaiveTime = chrono::NaiveTime::from_hms(21, 0, 0);
+ static ref NINE_AM: chrono::NaiveTime = chrono::NaiveTime::from_hms(9, 0, 0);
+ static ref NINE_PM: chrono::NaiveTime = chrono::NaiveTime::from_hms(21, 0, 0);
static ref PIANOMANS: Vec<TodayArgs> = vec![
by_url("https://www.youtube.com/watch?v=gxEPV4kolz0"),
@@ -18,18 +19,20 @@ pub fn pianoman(dt: chrono::NaiveDateTime) -> TodayIter {
return Box::new(empty());
}
- let diff = {
- let result = *TARGET_TIME - dt.time();
- if result < chrono::Duration::zero() {
- -result
- } else {
- result
- }
- };
+ let near_9am = duration_abs(*NINE_AM - dt.time()) <= Duration::minutes(5);
+ let near_9pm = duration_abs(*NINE_PM - dt.time()) <= Duration::minutes(5);
- if diff > Duration::minutes(5) {
+ if !near_9am && !near_9pm {
return Box::new(empty());
}
Box::new(PIANOMANS.iter().cloned())
}
+
+fn duration_abs(d: Duration) -> Duration {
+ if d < chrono::Duration::zero() {
+ -d
+ } else {
+ d
+ }
+}