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

Port from_timestamp_millis() (#818) to 0.4.x #823

Merged
merged 3 commits into from Sep 19, 2022
Merged

Conversation

djc
Copy link
Contributor

@djc djc commented Sep 19, 2022

Added some changes to deduplicate logic in the code.

@djc djc requested a review from esheppa September 19, 2022 09:49
@djc djc changed the base branch from main to 0.4.x September 19, 2022 09:50
pub fn from_timestamp_millis(millis: i64) -> Option<NaiveDateTime> {
let mut secs = millis / 1000;
if millis < 0 {
secs = secs.checked_sub(1)?;
Copy link
Collaborator

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)

Copy link
Contributor Author

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...

@djc djc force-pushed the 0.4.x-timestamp-millis branch 3 times, most recently from 15eb471 to 29ba499 Compare September 19, 2022 12:12
Copy link
Collaborator

@esheppa esheppa left a 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

@djc djc merged commit 147089b into 0.4.x Sep 19, 2022
@djc djc deleted the 0.4.x-timestamp-millis branch September 19, 2022 13:36
@djc
Copy link
Contributor Author

djc commented Sep 19, 2022

Hmm, let's try a bit more -- we should be a little more forceful about getting authors to target 0.4.x, I think.

@Pscheidl
Copy link
Contributor

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.

@djc
Copy link
Contributor Author

djc commented Sep 20, 2022

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 abs() call -- since abs() will internally call is_negative() anyway, branching in order to prevent an abs() call doesn't actually help -- it will have the same number of branches in the case it's not needed, and an extra branch in the case it is needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants