Skip to content

Commit 1198c8c

Browse files
committed
Fix for DateTimeTest.
1 parent 1b9de21 commit 1198c8c

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

src/test/java/testsuite/simple/DateTimeTest.java

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2444,6 +2444,9 @@ public void testOffsetTimeSetters() throws Exception {
24442444
public void testOffsetDatetimeSetters() throws Exception {
24452445
boolean withFract = versionMeetsMinimum(5, 6, 4); // fractional seconds are not supported in previous versions
24462446
boolean allowsOffset = versionMeetsMinimum(8, 0, 19);
2447+
// Starting from MySQL 8.0.22 server also converts TIMESTAMP_WITH_TIMEZONE value to the server time zone for column types other than TIMESTAMP and DATETIME.
2448+
// In MySQL 8.0.26 it was reverted.
2449+
boolean serverConvertsTzForAllTypes = versionMeetsMinimum(8, 0, 22) && !versionMeetsMinimum(8, 0, 26);
24472450

24482451
createTable(tYear, "(id INT, d YEAR)");
24492452
createTable(tDate, "(id INT, d DATE)");
@@ -2463,6 +2466,8 @@ public void testOffsetDatetimeSetters() throws Exception {
24632466
TimeZone serverTz;
24642467
try (Connection testConn = getConnectionWithProps(props)) {
24652468
serverTz = ((MysqlConnection) testConn).getSession().getServerSession().getSessionTimeZone();
2469+
System.out.println("Local tz: " + TimeZone.getDefault());
2470+
System.out.println("Server tz: " + serverTz);
24662471
}
24672472

24682473
OffsetDateTime odt_20200101_120000_123456_05_00 = OffsetDateTime.of(2020, 1, 1, 12, 00, 00, withFract ? 123456000 : 0, ZoneOffset.ofHours(5));
@@ -2531,15 +2536,15 @@ public void testOffsetDatetimeSetters() throws Exception {
25312536
.format(useSSPS ? TimeUtil.DATE_FORMATTER : DateTimeFormatter.ofPattern("20HH-mm-ss"));
25322537
// Starting from MySQL 8.0.22 TIMESTAMP_WITH_TIMEZONE value is also converted to the server time zone by server
25332538
// for column types other than TIMESTAMP or DATETIME
2534-
String expDateChar = versionMeetsMinimum(8, 0, 22)
2539+
String expDateChar = serverConvertsTzForAllTypes
25352540
? odt_20200101_120000_123456_05_00.atZoneSameInstant(sessionTz.toZoneId()).format(TimeUtil.DATE_FORMATTER)
25362541
: odt_20200101_120000_123456_05_00.format(TimeUtil.DATE_FORMATTER);
25372542
String expDateTS = zdt_TS_on_wire.format(TimeUtil.DATE_FORMATTER);
25382543

25392544
String expTimeNoMs = zdt_20200101_120000_123456_on_wire.format(TimeUtil.TIME_FORMATTER_NO_FRACT_NO_OFFSET);
25402545
String expTime = zdt_20200101_120000_123456_on_wire.format(timeFmt);
25412546

2542-
String expTime2 = versionMeetsMinimum(8, 0, 22)
2547+
String expTime2 = serverConvertsTzForAllTypes
25432548
? odt_20200101_120000_123456_05_00.atZoneSameInstant(sessionTz.toZoneId()).format(timeFmt)
25442549
: odt_20200101_120000_123456_05_00.format(timeFmt);
25452550
String expTimeTS = zdt_TS_on_wire.format(timeFmt);
@@ -2815,6 +2820,9 @@ public void testOffsetDatetimeSetters() throws Exception {
28152820
public void testZonedDatetimeSetters() throws Exception {
28162821
boolean withFract = versionMeetsMinimum(5, 6, 4); // fractional seconds are not supported in previous versions
28172822
boolean allowsOffset = versionMeetsMinimum(8, 0, 19);
2823+
// Starting from MySQL 8.0.22 server also converts TIMESTAMP_WITH_TIMEZONE value to the server time zone for column types other than TIMESTAMP and DATETIME.
2824+
// In MySQL 8.0.26 it was reverted.
2825+
boolean serverConvertsTzForAllTypes = versionMeetsMinimum(8, 0, 22) && !versionMeetsMinimum(8, 0, 26);
28182826

28192827
createTable(tYear, "(id INT, d YEAR)");
28202828
createTable(tDate, "(id INT, d DATE)");
@@ -2832,6 +2840,8 @@ public void testZonedDatetimeSetters() throws Exception {
28322840
TimeZone serverTz;
28332841
try (Connection testConn = getConnectionWithProps(props)) {
28342842
serverTz = ((MysqlConnection) testConn).getSession().getServerSession().getSessionTimeZone();
2843+
System.out.println("Local tz: " + TimeZone.getDefault());
2844+
System.out.println("Server tz: " + serverTz);
28352845
}
28362846

28372847
ZonedDateTime zdt_20200101_120000_123456_05_00 = ZonedDateTime.of(withFract ? ldt_20200101_120000_123456 : ldt_20200101_120000_123456.withNano(0),
@@ -2900,14 +2910,14 @@ public void testZonedDatetimeSetters() throws Exception {
29002910
.format(useSSPS ? TimeUtil.DATE_FORMATTER : DateTimeFormatter.ofPattern("20HH-mm-ss"));
29012911
// Starting from MySQL 8.0.22 TIMESTAMP_WITH_TIMEZONE value is also converted to the server time zone by server
29022912
// for column types other than TIMESTAMP or DATETIME
2903-
String expDateChar = versionMeetsMinimum(8, 0, 22)
2913+
String expDateChar = serverConvertsTzForAllTypes
29042914
? zdt_20200101_120000_123456_05_00.withZoneSameInstant(sessionTz.toZoneId()).format(TimeUtil.DATE_FORMATTER)
29052915
: zdt_20200101_120000_123456_05_00.format(TimeUtil.DATE_FORMATTER);
29062916
String expDateTS = zdt_TS_on_wire.format(TimeUtil.DATE_FORMATTER);
29072917

29082918
String expTimeNoMs = zdt_20200101_120000_123456_on_wire.format(TimeUtil.TIME_FORMATTER_NO_FRACT_NO_OFFSET);
29092919
String expTime = zdt_20200101_120000_123456_on_wire.format(timeFmt);
2910-
String expTime2 = versionMeetsMinimum(8, 0, 22)
2920+
String expTime2 = serverConvertsTzForAllTypes
29112921
? zdt_20200101_120000_123456_05_00.withZoneSameInstant(sessionTz.toZoneId()).format(timeFmt)
29122922
: zdt_20200101_120000_123456_05_00.format(timeFmt);
29132923
String expTimeTS = zdt_TS_on_wire.format(timeFmt);
@@ -3389,9 +3399,10 @@ void setObjectFromTz(Properties props, String tableName, Object parameter, SQLTy
33893399
testConn = this.utcConnections.get(getKey(props));
33903400
Statement localStmt = testConn.createStatement();
33913401
localStmt.execute("set @@time_zone='+00:00'");
3392-
ResultSet localRs = localStmt.executeQuery("SELECT * FROM " + tableName + " WHERE id = " + id + " AND d = '" + expectedUTCValue + "'"
3393-
+ (expectedUnixTimestamp != null ? " AND unix_timestamp(d) = " + expectedUnixTimestamp : ""));
3394-
assertTrue(localRs.next());
3402+
String sql = "SELECT * FROM " + tableName + " WHERE id = " + id + " AND d = '" + expectedUTCValue + "'"
3403+
+ (expectedUnixTimestamp != null ? " AND unix_timestamp(d) = " + expectedUnixTimestamp : "");
3404+
ResultSet localRs = localStmt.executeQuery(sql);
3405+
assertTrue(localRs.next(), parameter + "\n" + targetSqlType + "\n" + senderTz + "\n" + useMethod + "\n" + sql);
33953406
localStmt.close();
33963407
}
33973408
} finally {

0 commit comments

Comments
 (0)