Add IFC month retrieval

This commit is contained in:
Savanni D'Gerinel 2023-08-03 00:25:23 -04:00
parent fa8391cea0
commit 1ac7ce43f2
3 changed files with 7671 additions and 1 deletions

7647
dashboard/Cargo.nix Normal file

File diff suppressed because it is too large Load Diff

View File

@ -87,6 +87,11 @@
buildRustCrateForPkgs = customBuildInfo; buildRustCrateForPkgs = customBuildInfo;
release = true; release = true;
}).rootCrate.build; }).rootCrate.build;
dashboard = (import ./dashboard/Cargo.nix {
inherit pkgs;
release = true;
}).rootCrate.build;
}; };
hydraJobs = { hydraJobs = {

View File

@ -89,6 +89,12 @@ impl From<u32> for Month {
} }
} }
impl From<u8> for Month {
fn from(val: u8) -> Month {
Month::from(val as u32)
}
}
impl From<Month> for String { impl From<Month> for String {
fn from(val: Month) -> String { fn from(val: Month) -> String {
match val { match val {
@ -153,7 +159,11 @@ impl IFC {
} }
pub fn month_ifc(&self) -> Month { pub fn month_ifc(&self) -> Month {
Month::from(self.month()) match *self {
IFC::Day(Day { month, .. }) => Month::from(month),
IFC::LeapDay(_) => Month::June,
IFC::YearDay(_) => Month::December,
}
} }
pub fn weekday_ifc(&self) -> DayOfWeek { pub fn weekday_ifc(&self) -> DayOfWeek {
@ -477,6 +487,14 @@ mod tests {
); );
} }
#[test]
fn it_expresses_month() {
assert_eq!(IFC::ymd(12022, 1, 4).unwrap().month_ifc(), Month::January);
assert_eq!(IFC::ymd(12022, 12, 1).unwrap().month_ifc(), Month::November);
assert_eq!(IFC::leap_day(12020).unwrap().month_ifc(), Month::June);
assert_eq!(IFC::year_day(12020).month_ifc(), Month::December);
}
#[test] #[test]
fn it_reports_ordinal_days() { fn it_reports_ordinal_days() {
assert_eq!(IFC::ymd(12022, 1, 1).unwrap().day_ordinal(), 1); assert_eq!(IFC::ymd(12022, 1, 1).unwrap().day_ordinal(), 1);