Skip to content

days_in_month

The number of days in month of year.

use helpers4::date::days_in_month;

Cargo feature date (enabled by default). To compile only this module:

cargo add helpers4 --no-default-features --features date

or in Cargo.toml:

[dependencies]
helpers4 = { version = "0.0.6", default-features = false, features = ["date"] }
pub fn days_in_month(year: i32, month: u8) -> Option<u8>
ParameterTypeDescription
yeari32The year, which decides whether February has 28 or 29 days.
monthu8The month, 1 (January) to 12 (December).

Option<u8> — The number of days, or None when month is not in 1..=12.

use helpers4::date::days_in_month;

assert_eq!(days_in_month(2024, 2), Some(29));
assert_eq!(days_in_month(2023, 2), Some(28));
assert_eq!(days_in_month(2023, 4), Some(30));
assert_eq!(days_in_month(2023, 13), None);

src/date/days_in_month.rs