1use serde::Deserialize;
2
3#[derive(Debug, Copy, Clone, PartialEq, Eq, Deserialize, Hash)]
4pub enum DayPeriod {
5 Night,
6 Morning,
7 Noon,
8 Evening,
9}
10
11impl From<f64> for DayPeriod {
12 fn from(time_of_day: f64) -> Self {
13 let tod = time_of_day.rem_euclid(60.0 * 60.0 * 24.0);
14 if tod < 60.0 * 60.0 * 6.0 {
15 DayPeriod::Night
16 } else if tod < 60.0 * 60.0 * 11.0 {
17 DayPeriod::Morning
18 } else if tod < 60.0 * 60.0 * 16.0 {
19 DayPeriod::Noon
20 } else if tod < 60.0 * 60.0 * 19.0 {
21 DayPeriod::Evening
22 } else {
23 DayPeriod::Night
24 }
25 }
26}
27
28impl DayPeriod {
29 pub fn is_dark(&self) -> bool { *self == DayPeriod::Night }
30
31 pub fn is_light(&self) -> bool { !self.is_dark() }
32}