-
Notifications
You must be signed in to change notification settings - Fork 20
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
Conversation
There was a problem hiding this 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 { |
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice catch 🫠
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.