Skip to content

Implement posix resolution for month-week-day#214

Merged
jedel1043 merged 1 commit intomainfrom
posix-mwd
Feb 24, 2025
Merged

Implement posix resolution for month-week-day#214
jedel1043 merged 1 commit intomainfrom
posix-mwd

Conversation

@jedel1043
Copy link
Copy Markdown
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
Copy Markdown
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

Comment thread src/utils.rs

#[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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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.

Comment thread src/tzdb.rs
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
Copy Markdown
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
Copy Markdown
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.

Comment thread src/utils.rs
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
Copy Markdown
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
@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