Skip to content

Implement posix resolution for month-week-day #214

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

Merged
merged 1 commit into from
Feb 24, 2025
Merged

Implement posix resolution for month-week-day #214

merged 1 commit into from
Feb 24, 2025

Conversation

jedel1043
Copy link
Member

Phew, that was an adventure. This also adds a test that verifies that the mwd resolution works... on the thin tzdb that jiff bundles. The local UNIX database already has the year 2028 on its transition table, so in that case it just tests that the transition is correctly fetched.

@jedel1043 jedel1043 added C-enhancement New feature or request C-internal Internal library improvements labels Feb 24, 2025
@jedel1043 jedel1043 requested a review from nekevss February 24, 2025 15:25
Copy link
Member

@nekevss nekevss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me.

A couple nits, but nothing non-blocking

@@ -95,7 +95,7 @@ pub(crate) fn ymd_from_epoch_milliseconds(epoch_milliseconds: i64) -> (i32, u8,
}

#[cfg(feature = "tzdb")]
fn month_to_day(m: u8, leap_day: u16) -> u16 {
pub(crate) fn month_to_day(m: u8, leap_day: u16) -> u16 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: can this be documented to be a zero base month (mainly important because the neri-schneider calculations are 1 based).

Copy link
Member Author

@jedel1043 jedel1043 Feb 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should be more consistent about this? I wouldn't be against basing everything on 1 instead of having mixed bases

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that's fine with me.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! I'll do the cleanup in a separate PR.

TransitionDay::NoLeap(day) => day - 1,
TransitionDay::WithLeap(day) => day,
TransitionDay::Mwd(month, week, day) => {
let days_to_month = utils::month_to_day((month - 1) as u8, leap_day);
Copy link
Member

@nekevss nekevss Feb 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: it may be a bit more clear for this to be renamed from month_to_day -> month_to_day_of_year.

I think I had originally written this function, and looking back I think the name lacks a bit of clarity.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm planning on addressing this in a future cleanup that makes the names on the utils module a bit more consistent.

pub(crate) fn epoch_seconds_to_day_of_week(t: i64) -> u16 {
(((t / 86_400) + 4) % 7) as u16
pub(crate) fn epoch_seconds_to_day_of_week(t: i64) -> u8 {
((t / 86_400) + 4).rem_euclid(7) as u8
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice catch 🫠

@jedel1043 jedel1043 merged commit 91e8262 into main Feb 24, 2025
8 checks passed
@jedel1043 jedel1043 deleted the posix-mwd branch February 24, 2025 21:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-enhancement New feature or request C-internal Internal library improvements
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants