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

Projects
None yet
5 participants
@vlsi
Copy link
Member

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

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

@vlsi vlsi added this to the 42.2.3 milestone Jun 6, 2018

@codecov-io

This comment has been minimized.

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

This comment has been minimized.

Copy link
Member

davecramer commented Jun 6, 2018

LGTM

nanos = 0;
timeMillis++;
} else if (nanos % 1000 >= 500) {
nanos = nanos + 1000 - nanos % 1000;

This comment has been minimized.

@bokken

bokken Jun 7, 2018

Member

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

@lukeindykiewicz
Copy link

lukeindykiewicz left a comment

lgtm, just some minor suggestions

return "24:00:00";
}

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

This comment has been minimized.

@lukeindykiewicz

lukeindykiewicz Jun 8, 2018

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

This comment has been minimized.

@vlsi

vlsi Jun 8, 2018

Author Member

Any ideas for the function name?

This comment has been minimized.

@lukeindykiewicz

lukeindykiewicz Jun 8, 2018

isNanoCarry?
isNanoOverflow may be misleading.

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

This comment has been minimized.

@lukeindykiewicz

lukeindykiewicz Jun 8, 2018

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) {

This comment has been minimized.

@lukeindykiewicz

@vlsi vlsi removed the needs-review label Jun 8, 2018

@vlsi vlsi merged commit 4dc98be into pgjdbc:master Jun 8, 2018

2 checks passed

codecov/project Absolute coverage decreased by -14.55% but relative coverage increased by +14.73% compared to eaa0aca
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details

rhavermans added a commit to bolcom/pgjdbc that referenced this pull request Jul 13, 2018

fix: adjust date, hour, minute, second when rounding timestamp (pgjdb…
…c#1212)

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

fixes pgjdbc#1211

rhavermans added a commit to bolcom/pgjdbc that referenced this pull request Jul 13, 2018

fix: adjust date, hour, minute, second when rounding timestamp (pgjdb…
…c#1212)

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

fixes pgjdbc#1211
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.