1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
//! Timekeeping datasets including weekdays and months.
#![allow(missing_docs)]
#![allow(clippy::missing_docs_in_private_items)]
dataset_enum! {
/// The days of the week
pub enum Day {
/// [Monday](https://en.wikipedia.org/wiki/Monday) is the first day of the week
Monday = 1,
/// [Tuesday](https://en.wikipedia.org/wiki/Tuesday) is the second day of the week
Tuesday = 2,
/// [Wednesday](https://en.wikipedia.org/wiki/Wednesday) is the third day of the week
Wednesday = 3,
/// [Thursday](https://en.wikipedia.org/wiki/Thursday) is the fourth day of the week
Thursday = 4,
/// [Friday](https://en.wikipedia.org/wiki/Friday) is the fifth day of the week
Friday = 5,
/// [Saturday](https://en.wikipedia.org/wiki/Saturday) is the sixth day of the week
Saturday = 6,
/// [Sunday](https://en.wikipedia.org/wiki/Sunday) is the seventh day of the week
Sunday = 7,
}
}
dataset_enum! {
/// The months of the year
pub enum Month {
/// [January](https://en.wikipedia.org/wiki/January) is the first month of the year
January = 1,
/// [February](https://en.wikipedia.org/wiki/February) is the second month of the year
February = 2,
/// [March](https://en.wikipedia.org/wiki/March) is the third month of the year
March = 3,
/// [April](https://en.wikipedia.org/wiki/April) is the fourth month of the year
April = 4,
/// [May](https://en.wikipedia.org/wiki/May) is the fifth month of the year
May = 5,
/// [June](https://en.wikipedia.org/wiki/June) is the sixth month of the year
June = 6,
/// [July](https://en.wikipedia.org/wiki/July) is the seventh month of the year
July = 7,
/// [August](https://en.wikipedia.org/wiki/August) is the eighth month of the year
August = 8,
/// [September](https://en.wikipedia.org/wiki/September) is the ninth month of the year
September = 9,
/// [October](https://en.wikipedia.org/wiki/October) is the tenth month of the year
October = 10,
/// [November](https://en.wikipedia.org/wiki/November) is the eleventh month of the year
November = 11,
/// [December](https://en.wikipedia.org/wiki/December) is the twelfth month of the year
December = 12,
}
}
dataset_enum! {
/// The four meteorological seasons in Northern Hemisphere calendar order.
///
/// This order is a teaching convention and does not apply to both hemispheres.
///
/// # Examples
/// ```
/// use hodgepodge::Season;
///
/// let vacation = Season::Summer;
/// assert_eq!(vacation as u8, 3);
/// ```
pub enum Season {
/// [Winter](https://en.wikipedia.org/wiki/Winter) is the first season of the year.
Winter = 1,
/// [Spring](https://en.wikipedia.org/wiki/Spring_(season)) is the second season of the year.
Spring = 2,
/// [Summer](https://en.wikipedia.org/wiki/Summer) is the third season of the year.
Summer = 3,
/// [Fall](https://en.wikipedia.org/wiki/Autumn) (autumn) is the fourth season of the year.
Fall = 4,
}
}
dataset_enum! {
/// Fiscal quarters in chronological order.
///
/// # Examples
/// ```
/// use hodgepodge::Quarter;
///
/// let reporting_period = Quarter::Q4;
/// assert_eq!(reporting_period as u8, 4);
/// ```
pub enum Quarter {
/// The first quarter of the fiscal year.
Q1 = 1,
/// The second quarter of the fiscal year.
Q2 = 2,
/// The third quarter of the fiscal year.
Q3 = 3,
/// The fourth quarter of the fiscal year.
Q4 = 4,
}
}
#[cfg(all(test, feature = "strum"))]
mod tests {
use super::{Quarter, Season};
use crate::{EnumCount, IntoEnumIterator};
#[test]
fn seasons_iterate_in_calendar_order() {
let observed: Vec<u8> = Season::iter().map(|season| season as u8).collect();
assert_eq!(observed, vec![1, 2, 3, 4]);
}
#[test]
fn seasons_count_matches_four() {
assert_eq!(<Season as EnumCount>::COUNT, 4);
}
#[test]
fn quarters_iterate_in_chronological_order() {
let observed: Vec<u8> = Quarter::iter().map(|quarter| quarter as u8).collect();
assert_eq!(observed, vec![1, 2, 3, 4]);
}
#[test]
fn quarters_count_matches_four() {
assert_eq!(<Quarter as EnumCount>::COUNT, 4);
}
}