Skip to content

Commit

Permalink
Added length function to Month so that I don't have to use time crate
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielPoprawski committed Dec 20, 2024
1 parent 8b86349 commit 323737a
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/month.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,22 @@ impl Month {
Month::December => "December",
}
}

/// Get the length of the month in a given year
pub const fn length(&self, year: i32) -> u8 {
match *self {

Check warning on line 167 in src/month.rs

View check run for this annotation

Codecov / codecov/patch

src/month.rs#L166-L167

Added lines #L166 - L167 were not covered by tests
Month::January
| Month::March
| Month::May
| Month::July
| Month::August
| Month::October
| Month::December => 31,
Month::April | Month::June | Month::September | Month::November => 30,
Month::February if year % 4 == 0 && (year % 25 != 0 || year % 16 == 0) => 29,
Month::February => 28,

Check warning on line 177 in src/month.rs

View check run for this annotation

Codecov / codecov/patch

src/month.rs#L174-L177

Added lines #L174 - L177 were not covered by tests
}
}

Check warning on line 179 in src/month.rs

View check run for this annotation

Codecov / codecov/patch

src/month.rs#L179

Added line #L179 was not covered by tests
}

impl TryFrom<u8> for Month {
Expand Down

0 comments on commit 323737a

Please sign in to comment.