-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
chore(rust): fix chrono deprecation warnings #14928
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.
nice!
if v >= 0 { | ||
NaiveDateTime::from_timestamp_opt( | ||
// extract seconds from milliseconds | ||
v / MILLISECONDS, | ||
// discard extracted seconds and convert milliseconds to nanoseconds | ||
(v % MILLISECONDS * MICROSECONDS) as u32, | ||
) | ||
} else { | ||
let secs_rem = (v / MILLISECONDS, v % MILLISECONDS); | ||
if secs_rem.1 == 0 { | ||
// whole/integer seconds; no adjustment required | ||
NaiveDateTime::from_timestamp_opt(secs_rem.0, 0) | ||
} else { | ||
// negative values with fractional seconds require 'div_floor' rounding behaviour. | ||
// (which isn't yet stabilised: https://github.com/rust-lang/rust/issues/88581) | ||
NaiveDateTime::from_timestamp_opt( | ||
secs_rem.0 - 1, | ||
(NANOSECONDS + (v % MILLISECONDS * MICROSECONDS)) as u32, | ||
) | ||
} | ||
} | ||
let delta = TimeDelta::try_milliseconds(v)?; | ||
NaiveDateTime::UNIX_EPOCH.checked_add_signed(delta) |
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.
so satisfying 😍
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #14928 +/- ##
==========================================
+ Coverage 81.01% 81.03% +0.01%
==========================================
Files 1332 1332
Lines 172870 172852 -18
Branches 2458 2458
==========================================
+ Hits 140054 140066 +12
+ Misses 32348 32317 -31
- Partials 468 469 +1 ☔ View full report in Codecov by Sentry. |
@MarcoGorelli Could you check this out to make sure I didn't mess stuff up?