Skip to content

Conversation

@nekevss
Copy link
Member

@nekevss nekevss commented Dec 26, 2025

This is going to be a first in a string of PRs to implement a zero-copy compiled data zoneinfo provider.

Fixes a bug in the POSIX time zone calculations where we weren't correctly handling the time overflow on some edge cases.

@nekevss nekevss requested review from a team and Manishearth December 26, 2025 18:43
Copy link
Contributor

@Manishearth Manishearth left a comment

Choose a reason for hiding this comment

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

I'm not quite sure how this overflow works, can you add comments?


impl PosixDate {
pub(crate) fn from_rule(rule: &Rule) -> Self {
pub(crate) fn from_rule(rule: &Rule) -> (Self, i64) {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: document return type

@nekevss nekevss requested review from a team and Manishearth December 26, 2025 20:59
Copy link
Contributor

@Manishearth Manishearth left a comment

Choose a reason for hiding this comment

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

Still don't fully understand why something would be "off the target weekday" but that's fine

QualifiedTime::Local(time) => time,
QualifiedTime::Standard(standard_time) => standard_time.add(rule.save),
QualifiedTime::Universal(universal_time) => universal_time.add(offset).add(savings),
QualifiedTime::Local(time) => time.add(Time::from_seconds(time_overflow)),
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: probably just add to the time outside the match, let time = time.add(overflow)

// This ensures that day_of_month being 1 aligns with Sun = 0, for
// Sun>=1 purposes.
//
// The primary purpose for this approach as noted in zic.c is to support
Copy link
Contributor

Choose a reason for hiding this comment

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

link? I don't find any such comment but I might not be looking hard enough

https://github.com/eggert/tz/blob/main/zic.c

Copy link
Member Author

Choose a reason for hiding this comment

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

The comment is from the commit history. I can link to it.

@nekevss nekevss merged commit 22b1ce8 into main Dec 26, 2025
8 checks passed
Comment on lines +447 to +460
impl WeekDay {
pub(crate) fn from_u8(value: u8) -> Self {
match value {
0 => Self::Sun,
1 => Self::Mon,
2 => Self::Tues,
3 => Self::Wed,
4 => Self::Thurs,
5 => Self::Fri,
6 => Self::Sat,
_ => unreachable!("invalid week day value"),
}
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I feel like, even for pub(crate) this should return a Option<Self> where the caller should be responsible for doing the unreachable assertion, which holds in the case of zoneinfo/src/posix.rs:180

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree

Copy link
Contributor

Choose a reason for hiding this comment

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

Probably this is something that needs fixing in more than one area. Maybe I can look into that

Copy link
Member Author

Choose a reason for hiding this comment

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

It's probably fair. I debated it myself, but decided against it because it was an internal operation that is ultimately unreachable.

But that being asserted by the caller is definitely a better argument.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants