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

Fix rounding when handling negative timestamps #580

Merged
merged 1 commit into from
Mar 19, 2022

Conversation

sigurdm
Copy link
Collaborator

@sigurdm sigurdm commented Feb 24, 2022

Fixes: #577

@mit-mit mit-mit requested a review from osa1 March 15, 2022 13:59
Copy link
Member

@osa1 osa1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me, thanks.

I'm new to Dart so it took a while for me to get this. "Microseconds since epoch" value is a 64-bit signed integer. The line changed in this PR:

target.seconds = Int64(micros ~/ Duration.microsecondsPerSecond);

truncates a negative number in some cases and effectively does ceiling division when micros is negative. In the original repro, microsecondsSinceEpoch value is -1262393999999000. This program demonstrates the issue:

void main() {
  print(-1262393999999000 / 1000000);           // -1262393999.999
  print(-1262393999999000 ~/ 1000000);          // -1262393999
  print((-1262393999999000 / 1000000).floor()); // -1262394000
}

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.

Dates before epoch time cannot be converted into a Timestamp and back to a Dart DateTime properly.
2 participants