pendulum icon indicating copy to clipboard operation
pendulum copied to clipboard

rust: Use i64 for internal unix timestamps

Open bdrung opened this issue 1 year ago • 2 comments

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

Pull Request Check List

  • [ ] Added tests for changed code.
  • [ ] Updated documentation for changed code.

bdrung avatar Sep 05 '24 11:09 bdrung

CodSpeed Performance Report

Merging #842 will not alter performance

Comparing bdrung:32-bit (f2b0351) with master (83db0b9)

Summary

✅ 1 untouched benchmarks

codspeed-hq[bot] avatar Sep 22 '24 15:09 codspeed-hq[bot]

Thank you for your patch.

Secrus avatar Sep 22 '24 16:09 Secrus

Please rebase your changes with master to fix the failing pipeline

Secrus avatar Nov 21 '24 09:11 Secrus

Rebased on master.

bdrung avatar Nov 21 '24 09:11 bdrung

Thank you for the fix

Secrus avatar Nov 21 '24 09:11 Secrus