Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added length function to Month so that I don't have to use time crate #1643

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
Month::December => "December",
}
}

/// Get the length of the month in a given year
pub const fn len(&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 % 100 != 0 || year % 400 == 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
Loading