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: adjust date, hour, minute, second when rounding timestamp #1212

Merged
merged 3 commits into from
Jun 8, 2018

Conversation

vlsi
Copy link
Member

@vlsi vlsi commented Jun 6, 2018

PostgreSQL supports microsecond resolution only, so PgJDBC rounds
nanoseconds to micros. When that happens the number of seconds, minutes, etc
might change as well

fixes #1211

PostgreSQL supports microsecond resolution only, so PgJDBC rounds
nanoseconds to micros. When that happens the number of seconds, minutes, etc
might change as well

fixes pgjdbc#1211
@vlsi vlsi added this to the 42.2.3 milestone Jun 6, 2018
@codecov-io
Copy link

codecov-io commented Jun 6, 2018

Codecov Report

Merging #1212 into master will decrease coverage by 14.55%.
The diff coverage is 84%.

@@             Coverage Diff              @@
##             master   #1212       +/-   ##
============================================
- Coverage     69.26%   54.7%   -14.56%     
- Complexity     3807    3812        +5     
============================================
  Files           171     186       +15     
  Lines         15769   19993     +4224     
  Branches       2578    2698      +120     
============================================
+ Hits          10922   10937       +15     
- Misses         3613    7821     +4208     
- Partials       1234    1235        +1

@davecramer
Copy link
Member

LGTM

@vlsi vlsi added the triage/needs-review Issue that needs a review - remove label if all is clear label Jun 6, 2018
nanos = 0;
timeMillis++;
} else if (nanos % 1000 >= 500) {
nanos = nanos + 1000 - nanos % 1000;
Copy link
Member

Choose a reason for hiding this comment

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

it appears appendTime now simply truncates at micro precision. that would seem to mean that nanos += 1000; would be sufficient here.

Copy link

@lukeindykiewicz lukeindykiewicz left a comment

Choose a reason for hiding this comment

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

lgtm, just some minor suggestions

return "24:00:00";
}

int nano = localTime.getNano();
if (nano % 1000 >= 500) {

Choose a reason for hiding this comment

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

This expression (nano % 1000 >= 500) is used in more than one place, why don't extract it to a function?

Copy link
Member Author

Choose a reason for hiding this comment

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

Any ideas for the function name?

Choose a reason for hiding this comment

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

isNanoCarry?
isNanoOverflow may be misleading.

insertThenReadWithType(time, Types.TIME, "time_without_time_zone_column", Time.class);
assertEquals(Time.valueOf("24:00:00"), actual);
}

Choose a reason for hiding this comment

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

Please consider writing a test for year change, like for '2018-12-31 23:59:59.999999500' to prevent potential bugs after refactorings in the future.

* @param nanos nanosecond part of the time
* @return true when microsecond part of the time should be increased when rounding to microseconds
*/
private static boolean nanosExceed499(int nanos) {

Choose a reason for hiding this comment

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

👍

@vlsi vlsi removed the triage/needs-review Issue that needs a review - remove label if all is clear label Jun 8, 2018
@vlsi vlsi merged commit 4dc98be into pgjdbc:master Jun 8, 2018
davecramer pushed a commit to marschall/pgjdbc that referenced this pull request Aug 8, 2022
Implement proper rounding using a TemporalAdjuster that sets to nanos
to 0 instead of relying on them being truncated later.

See pgjdbc#1212
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.

Nanoseconds are rounded incorrectly 42.2.2
5 participants