-
Notifications
You must be signed in to change notification settings - Fork 542
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
Port from_timestamp_millis() (#818) to 0.4.x #823
Conversation
pub fn from_timestamp_millis(millis: i64) -> Option<NaiveDateTime> { | ||
let mut secs = millis / 1000; | ||
if millis < 0 { | ||
secs = secs.checked_sub(1)?; |
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.
I think we still need to include this part as well: NANOS_IN_SECOND.checked_sub(nsecs)?,
(in the millis < 0
case only)
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.
Oh yeah, good catch. Added a commit that enables CI to run on the 0.4.x branch, too...
15eb471
to
29ba499
Compare
Construct NaiveDateTime from millis since epoch
29ba499
to
ae6c377
Compare
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.
Looks good! Maybe backporting to 0.4.x
is cleaner - it keeps the history of the main
branch nicer as well
Hmm, let's try a bit more -- we should be a little more forceful about getting authors to target 0.4.x, I think. |
This version is cleaner, but should be slightly less efficient - two ifs instead of one and the 'abs' operation is always performed. Not sure if you care about the difference, just explaining the original implementation. |
Yeah -- unless someone wants to build benchmarks that show a substantial improvement, I'd rather opt for code that's easier to follow. As for the |
Added some changes to deduplicate logic in the code.