Skip to content
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

Stop vendoring saturating_abs #1124

Merged
merged 1 commit into from
Jun 4, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 2 additions & 13 deletions src/offset/local/tz_info/timezone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ impl<'a> TimeZoneRef<'a> {
// Check leap seconds
if !(self.leap_seconds.is_empty()
|| self.leap_seconds[0].unix_leap_time >= 0
&& saturating_abs(self.leap_seconds[0].correction) == 1)
&& self.leap_seconds[0].correction.saturating_abs() == 1)
{
return Err(Error::TimeZone("invalid leap second"));
}
Expand All @@ -336,7 +336,7 @@ impl<'a> TimeZoneRef<'a> {

let diff_unix_leap_time = x1.unix_leap_time.saturating_sub(x0.unix_leap_time);
let abs_diff_correction =
saturating_abs(x1.correction.saturating_sub(x0.correction));
x1.correction.saturating_sub(x0.correction).saturating_abs();

if !(diff_unix_leap_time >= min_interval && abs_diff_correction == 1) {
return Err(Error::TimeZone("invalid leap second"));
Expand Down Expand Up @@ -615,17 +615,6 @@ fn find_tz_file(path: impl AsRef<Path>) -> Result<File, Error> {
}
}

#[inline]
const fn saturating_abs(v: i32) -> i32 {
if v.is_positive() {
v
} else if v == i32::min_value() {
i32::max_value()
} else {
-v
}
}

// Possible system timezone directories
#[cfg(unix)]
const ZONE_INFO_DIRECTORIES: [&str; 4] =
Expand Down