2021-04-16 11:17:15 +00:00
|
|
|
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
|
2020-08-30 12:25:54 +00:00
|
|
|
pub enum DayPeriod {
|
|
|
|
Night,
|
|
|
|
Morning,
|
|
|
|
Noon,
|
|
|
|
Evening,
|
|
|
|
}
|
|
|
|
|
2020-10-07 02:23:20 +00:00
|
|
|
impl From<f64> for DayPeriod {
|
|
|
|
fn from(time_of_day: f64) -> Self {
|
|
|
|
let tod = time_of_day.rem_euclid(60.0 * 60.0 * 24.0);
|
2021-04-12 00:43:08 +00:00
|
|
|
if tod < 60.0 * 60.0 * 6.0 {
|
2020-10-07 02:23:20 +00:00
|
|
|
DayPeriod::Night
|
2021-04-12 00:43:08 +00:00
|
|
|
} else if tod < 60.0 * 60.0 * 11.0 {
|
2020-10-07 02:23:20 +00:00
|
|
|
DayPeriod::Morning
|
|
|
|
} else if tod < 60.0 * 60.0 * 16.0 {
|
|
|
|
DayPeriod::Noon
|
2021-04-12 00:43:08 +00:00
|
|
|
} else if tod < 60.0 * 60.0 * 19.0 {
|
2020-10-07 02:23:20 +00:00
|
|
|
DayPeriod::Evening
|
|
|
|
} else {
|
|
|
|
DayPeriod::Night
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-30 12:25:54 +00:00
|
|
|
impl DayPeriod {
|
2020-09-03 18:06:06 +00:00
|
|
|
pub fn is_dark(&self) -> bool { *self == DayPeriod::Night }
|
2020-08-30 12:25:54 +00:00
|
|
|
|
2020-09-03 18:06:06 +00:00
|
|
|
pub fn is_light(&self) -> bool { !self.is_dark() }
|
2020-08-30 12:25:54 +00:00
|
|
|
}
|