Function datealgo::isoweeks_in_year

source ·
pub const fn isoweeks_in_year(y: i32) -> u8
Expand description

Determine the number of ISO weeks in the given year

According to the ISO standard a year has 52 weeks, unless the first week of the year starts on a Thursday or the year is a leap year and the first week of the year starts on a Wednesday, in which case the year has 53 weeks.

Panics

Year must be between YEAR_MIN and YEAR_MAX. Bounds are checked using debug_assert only, so that the checks are not present in release builds, similar to integer overflow checks.

Examples

use datealgo::isoweeks_in_year;

assert_eq!(isoweeks_in_year(2023), 52);
assert_eq!(isoweeks_in_year(2024), 52);
assert_eq!(isoweeks_in_year(2025), 52);
assert_eq!(isoweeks_in_year(2026), 53);
assert_eq!(isoweeks_in_year(2027), 52);

Algorithm

Algorithm is hand crafted and not significantly optimized.