Skip to content

Commit 794d362

Browse files
committed
[misc] correct Date test depending on timezone
1 parent 609aa2d commit 794d362

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

src/test/java/org/mariadb/jdbc/integration/codec/DateTimeCodecTest.java

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -570,14 +570,13 @@ public void getDateTimezoneTestGmtm8(Connection conGmt8, ResultSet rs, TimeZone
570570
conGmt8.rollback();
571571
}
572572

573-
public void getDateTimezoneTestNormal(Connection conAuto, ResultSet rs)
574-
throws SQLException {
573+
public void getDateTimezoneTestNormal(Connection conAuto, ResultSet rs) throws SQLException {
575574

576575
assertEquals("2010-01-12 01:55:12.0", rs.getObject(1, Timestamp.class).toString());
577576

578577
conAuto.createStatement().execute("TRUNCATE TABLE DateTimeCodec3");
579578
try (PreparedStatement prep =
580-
conAuto.prepareStatement("INSERT INTO DateTimeCodec3 values (?,?)")) {
579+
conAuto.prepareStatement("INSERT INTO DateTimeCodec3 values (?,?)")) {
581580
prep.setInt(1, 5);
582581
prep.setString(2, "2010-01-12 01:55:12");
583582
prep.execute();
@@ -590,7 +589,8 @@ public void getDateTimezoneTestNormal(Connection conAuto, ResultSet rs)
590589

591590
java.sql.Statement stmt = conAuto.createStatement();
592591
stmt.execute("START TRANSACTION"); // if MAXSCALE ensure using WRITER
593-
try (PreparedStatement prepStmt = conAuto.prepareStatement("select * from DateTimeCodec3 order by id")) {
592+
try (PreparedStatement prepStmt =
593+
conAuto.prepareStatement("select * from DateTimeCodec3 order by id")) {
594594
rs = prepStmt.executeQuery();
595595
rs.next();
596596
assertEquals(5, rs.getInt(1));
@@ -605,7 +605,17 @@ public void getDateTimezoneTestNormal(Connection conAuto, ResultSet rs)
605605
if (offsetHour < 0) offsetHour = offsetHour * -1;
606606

607607
// test might fail if run in timezone with offset not rounded to hours
608-
assertEquals("2010-01-12T11:55:12" + ((offset < 0) ? "-" : "+") + ((offsetHour < 10) ? "0" : offsetHour / 10) + (offsetHour % 10) + ":00", rs.getObject(2, OffsetDateTime.class).toString());
608+
if (offsetHour == 0) {
609+
assertEquals("2010-01-12T11:55:12Z", rs.getObject(2, OffsetDateTime.class).toString());
610+
} else {
611+
assertEquals(
612+
"2010-01-12T11:55:12"
613+
+ ((offset < 0) ? "-" : "+")
614+
+ ((offsetHour < 10) ? "0" : offsetHour / 10)
615+
+ (offsetHour % 10)
616+
+ ":00",
617+
rs.getObject(2, OffsetDateTime.class).toString());
618+
}
609619
assertEquals("2010-01-12 11:55:12.0", rs.getTimestamp(2).toString());
610620
}
611621
conAuto.rollback();

0 commit comments

Comments
 (0)