-
Notifications
You must be signed in to change notification settings - Fork 819
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix #3224 - conversion for TIME '24:00' to LocalTime breaks in binary…
…-mode (#3225) * test: add tests for `TIME '24:00'` / LocalTime.MAX in binary-mode add tests which verify, that conversion of binary-transferred TIME/TIMETZ `24:00` to LocalTime currently fails * fix: handling of `TIME '24:00'` / LocalTime in binary-mode fixes conversion of TIME/TIMETZ `24:00` to LocalTime from binary. we now convert `24:00` to `LocalTime.MAX` instead of failing with `Invalid value for NanoOfDay`, which is now consistent with conversion from text. * test: remove superfluous delete at end of test `#setUp()` and `#tearDown()` manage the test-table's lifecycle. the test-table gets dropped at end of test anyway.
- Loading branch information
Showing
3 changed files
with
59 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ | |
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import org.postgresql.jdbc.TimestampUtils; | ||
import org.postgresql.util.ByteConverter; | ||
|
||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
@@ -22,7 +23,7 @@ class TimestampUtilsTest { | |
|
||
@BeforeEach | ||
void setUp() { | ||
timestampUtils = new TimestampUtils(true, TimeZone::getDefault); | ||
timestampUtils = new TimestampUtils(false, TimeZone::getDefault); | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
davecramer
Member
|
||
} | ||
|
||
@Test | ||
|
@@ -91,6 +92,37 @@ private void assertToLocalTime(String expectedOutput, String inputTime, String m | |
+ (message == null ? ": " + message : "")); | ||
} | ||
|
||
@Test | ||
void toLocalTimeBin() throws SQLException { | ||
assertToLocalTimeBin("00:00:00", 0L); | ||
|
||
assertToLocalTimeBin("00:00:00.1", 100_000L); | ||
assertToLocalTimeBin("00:00:00.12", 120_000L); | ||
assertToLocalTimeBin("00:00:00.123", 123_000L); | ||
assertToLocalTimeBin("00:00:00.1234", 123_400L); | ||
assertToLocalTimeBin("00:00:00.12345", 123_450L); | ||
assertToLocalTimeBin("00:00:00.123456", 123_456L); | ||
assertToLocalTimeBin("00:00:00.999999", 999_999L); | ||
|
||
assertToLocalTimeBin("23:59:59", 86_399_000_000L); | ||
assertToLocalTimeBin("23:59:59.999999", 86_399_999_999L); | ||
assertToLocalTimeBin(LocalTime.MAX.toString(), 86_400_000_000L, "LocalTime can't represent 24:00:00"); | ||
} | ||
|
||
private void assertToLocalTimeBin(String expectedOutput, long inputMicros) throws SQLException { | ||
assertToLocalTimeBin(expectedOutput, inputMicros, null); | ||
} | ||
|
||
private void assertToLocalTimeBin(String expectedOutput, long inputMicros, String message) throws SQLException { | ||
final byte[] bytes = new byte[8]; | ||
ByteConverter.int8(bytes, 0, inputMicros); | ||
assertEquals( | ||
LocalTime.parse(expectedOutput), | ||
timestampUtils.toLocalTimeBin(bytes), | ||
"timestampUtils.toLocalTime(" + inputMicros + ")" | ||
+ (message == null ? ": " + message : "")); | ||
} | ||
|
||
@Test | ||
void toStringOfOffsetTime() { | ||
assertToStringOfOffsetTime("00:00:00+00", "00:00:00+00:00"); | ||
|
What is the reason for the change? Do we need testing both true/false?