-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
2 changed files
with
44 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,39 @@ | ||
--- rust/src/helpers-orig.rs 2023-12-16 17:04:29 | ||
+++ rust/src/helpers.rs 2025-01-19 08:51:27 | ||
@@ -49,57 +49,57 @@ | ||
https://sources.debian.org/patches/pendulum/3.0.0-2/rust-Use-i64-for-internal-unix-timestamps.patch | ||
|
||
From: Benjamin Drung <[email protected]> | ||
Date: Thu, 5 Sep 2024 14:03:44 +0200 | ||
Subject: rust: Use i64 for internal unix timestamps | ||
|
||
pendulum 3.0.0 fails to build on 32-bit armhf: | ||
|
||
``` | ||
error: this arithmetic operation will overflow | ||
--> src/helpers.rs:59:20 | ||
| | ||
59 | seconds += ((146_097 - 10957) * SECS_PER_DAY as usize) as isize; | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ attempt to compute `135140_usize * 86400_usize`, which would overflow | ||
| | ||
= note: `#[deny(arithmetic_overflow)]` on by default | ||
``` | ||
|
||
`(146_097 - 10957) * SECS_PER_DAY` equals 11,676,096,000 which does not | ||
fit into 32 bit integers. | ||
|
||
Use i64 for the seconds variable while handling with the timestamp. Only | ||
convert in to `usize` once the timestamp is split into its components. | ||
|
||
Fixes https://github.com/sdispater/pendulum/issues/784 | ||
Ubuntu-Bug: https://bugs.launchpad.net/ubuntu/+source/pendulum/+bug/2079029 | ||
Forwarded: https://github.com/sdispater/pendulum/pull/842 | ||
--- | ||
rust/src/helpers.rs | 38 +++++++++++++++++++------------------- | ||
1 file changed, 19 insertions(+), 19 deletions(-) | ||
|
||
diff --git a/rust/src/helpers.rs b/rust/src/helpers.rs | ||
index 364075a..7927413 100644 | ||
--- a/rust/src/helpers.rs | ||
+++ b/rust/src/helpers.rs | ||
@@ -49,57 +49,57 @@ pub fn local_time( | ||
microsecond: usize, | ||
) -> (usize, usize, usize, usize, usize, usize, usize) { | ||
let mut year: usize = EPOCH_YEAR as usize; | ||
|
@@ -45,23 +78,23 @@ | |
} | ||
|
||
- let mut sec_per_4years = SECS_PER_4_YEARS[leap_year] as isize; | ||
+ let mut sec_per_4years = SECS_PER_4_YEARS[leap_year].into(); | ||
+ let mut sec_per_4years = SECS_PER_4_YEARS[leap_year].try_into().unwrap(); | ||
while seconds >= sec_per_4years { | ||
seconds -= sec_per_4years; | ||
year += 4; | ||
leap_year = 1; // 4-year, non century aligned | ||
- sec_per_4years = SECS_PER_4_YEARS[leap_year] as isize; | ||
+ sec_per_4years = SECS_PER_4_YEARS[leap_year].into(); | ||
+ sec_per_4years = SECS_PER_4_YEARS[leap_year].try_into().unwrap(); | ||
} | ||
|
||
- let mut sec_per_year = SECS_PER_YEAR[leap_year] as isize; | ||
+ let mut sec_per_year = SECS_PER_YEAR[leap_year].into(); | ||
+ let mut sec_per_year = SECS_PER_YEAR[leap_year].try_into().unwrap(); | ||
while seconds >= sec_per_year { | ||
seconds -= sec_per_year; | ||
year += 1; | ||
leap_year = 0; // non 4-year aligned | ||
- sec_per_year = SECS_PER_YEAR[leap_year] as isize; | ||
+ sec_per_year = SECS_PER_YEAR[leap_year].into(); | ||
+ sec_per_year = SECS_PER_YEAR[leap_year].try_into().unwrap(); | ||
} | ||
|
||
// Handle months and days | ||
|
@@ -73,7 +106,7 @@ | |
|
||
let mut month_offset: usize; | ||
while month != (TM_JANUARY + 1) { | ||
@@ -113,10 +113,10 @@ | ||
@@ -113,10 +113,10 @@ pub fn local_time( | ||
} | ||
|
||
// Handle hours, minutes and seconds | ||
|