Function datealgo::rd_to_isoweekdate
source · pub const fn rd_to_isoweekdate(rd: i32) -> (i32, u8, u8)Expand description
Convert Rata Die to ISO week date
Given a day counting from Unix epoch (January 1st, 1970) returns a (year, week, day of week) tuple. Week is the ISO week number, with the first week
of the year being the week containing the first Thursday of the year. Day of
week is between 1 and 7, with 1 meaning Monday and 7 meaning Sunday.
Compared to Gregorian date, the first one to three days of the year might belong to a week in the previous year, and the last one to three days of the year might belong to a week in the next year. Also some years have 53 weeks instead of 52.
Panics
Argument must be between RD_MIN and RD_MAX inclusive. 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::{rd_to_isoweekdate, date_to_rd};
assert_eq!(rd_to_isoweekdate(date_to_rd((2023, 5, 12))), (2023, 19, 5));
assert_eq!(rd_to_isoweekdate(date_to_rd((1970, 1, 1))), (1970, 1, 4));
assert_eq!(rd_to_isoweekdate(date_to_rd((2023, 1, 1))), (2022, 52, 7));
assert_eq!(rd_to_isoweekdate(date_to_rd((1979, 12, 31))), (1980, 1, 1));
assert_eq!(rd_to_isoweekdate(date_to_rd((1981, 12, 31))), (1981, 53, 4));
assert_eq!(rd_to_isoweekdate(date_to_rd((1982, 1, 1))), (1981, 53, 5));Algorithm
Algorithm is hand crafted and not significantly optimized.