baseunits_rs/time/
day_of_month.rs1use crate::time::{CalendarYearMonth, CalendarDate};
2
3#[derive(Debug, Clone, Eq, PartialEq, PartialOrd, Hash)]
4pub struct DayOfMonth(pub(crate) u32);
5
6impl DayOfMonth {
7 pub const MIN: u32 = 1;
8 pub const MAX: u32 = 31;
9
10 pub fn new(value: u32) -> Self {
11 if !(DayOfMonth::MIN <= value && value <= DayOfMonth::MAX) {
12 panic!(
13 "Illegal value for day of month: {:?}, please use a value between 1 and 31",
14 value
15 )
16 }
17 Self(value)
18 }
19
20 pub fn to_u32(&self) -> u32 {
21 self.0
22 }
23
24 pub fn is_appliable(&self, month: CalendarYearMonth) -> bool {
25 !month.as_last_day_of_month().is_before(self)
26 }
27
28 pub fn on(self, month: CalendarYearMonth) -> CalendarDate {
29 CalendarDate::new(month, self)
30 }
31
32 pub fn is_after(&self, other: &Self) -> bool {
33 !self.is_before(other) && self != other
34 }
35
36 pub fn is_before(&self, other: &Self) -> bool {
37 self.0 < other.0
38 }
39}