Skip to content

Commit b13af38

Browse files
committed
Fix for DateTimeTest according to changes in MySQL server.
1 parent 5c7b775 commit b13af38

File tree

1 file changed

+31
-16
lines changed

1 file changed

+31
-16
lines changed

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

+31-16
Original file line numberDiff line numberDiff line change
@@ -531,6 +531,8 @@ public void testSqlTimeSetters() throws Exception {
531531
.format(withFract ? TIME_FORMATTER_WITH_MILLIS_NO_OFFCET : TimeUtil.TIME_FORMATTER_NO_FRACT_NO_OFFSET)
532532
: expTimeNoMs;
533533

534+
String expDate8_0_28 = zdt_19700101_120000_123_at_senderTz.format(DateTimeFormatter.ofPattern("20HH-mm-ss"));
535+
534536
String expTimeNoMsCal = zdt_19700101_120000_123_at_calendarTz.toLocalTime()
535537
.format(TimeUtil.TIME_FORMATTER_NO_FRACT_NO_OFFSET);
536538
String expTimeCal = sendFractionalSeconds && sendTimeFract
@@ -568,7 +570,9 @@ public void testSqlTimeSetters() throws Exception {
568570

569571
/* Into DATE field */
570572

571-
String expDateErr = incorrectDateErr.replace("X", expTimeSendTimeFract);
573+
String expDateErr = incorrectDateErr.replace("X",
574+
useSSPS && !(sendTimeFract && sendFractionalSeconds) && versionMeetsMinimum(8, 0, 28) ? expDate8_0_28
575+
: expTimeSendTimeFract);
572576
String expDateErrWithCal = incorrectDateErr.replace("X", expTimeCal);
573577

574578
if (useSSPS) {
@@ -630,7 +634,9 @@ public void testSqlTimeSetters() throws Exception {
630634

631635
String expDatetime = expDate + " " + expTimeSendTimeFract;
632636
String expDatetimeWithCal = expDate + " " + expTimeCal;
633-
String expDatetimeErr = incorrectDatetimeErr.replace("X", expTimeSendTimeFract);
637+
String expDatetimeErr = incorrectDatetimeErr.replace("X",
638+
useSSPS && !(sendTimeFract && sendFractionalSeconds) && versionMeetsMinimum(8, 0, 28) ? expDate8_0_28
639+
: expTimeSendTimeFract);
634640
String expDatetimeErrWithCal = incorrectDatetimeErr.replace("X", expTimeCal);
635641

636642
if (useSSPS) {
@@ -1848,6 +1854,8 @@ public void testLocalTimeSetters() throws Exception {
18481854
String expTimeNoMs = zdt_no_date_120000_123456_on_wire.format(TimeUtil.TIME_FORMATTER_NO_FRACT_NO_OFFSET);
18491855
String expTime6 = zdt_no_date_120000_123456_on_wire.format(timeFmt);
18501856
String expTime9 = zdt_no_date_120000_123456_on_wire.format(timeFmtForChars);
1857+
String expTime8_0_28 = zdt_no_date_120000_123456_on_wire.format(DateTimeFormatter.ofPattern("20HH-mm-ss"));
1858+
18511859
String expDatetimeDef = zdt_no_date_120000_123456_on_wire
18521860
.format(useSSPS ? dateTimeFmt : DateTimeFormatter.ofPattern("20HH-mm-ss 00:00:00"));
18531861
String expDefTimestamp = zdt_no_date_120000_123456_on_wire.withZoneSameInstant(tz_UTC.toZoneId()).format(dateTimeFmt);
@@ -1860,9 +1868,13 @@ public void testLocalTimeSetters() throws Exception {
18601868
: "");
18611869

18621870
String expDateErr6 = incorrectDateErr.replace("X", expTime6);
1863-
String expDateErr9 = incorrectDateErr.replace("X", expTime9);
1871+
1872+
String expDateErr9 = incorrectDateErr.replace("X",
1873+
useSSPS && !sendFractionalSeconds && versionMeetsMinimum(8, 0, 28) ? expTime8_0_28 : expTime9);
1874+
18641875
String expDatetimeErr6 = incorrectDatetimeErr.replace("X", expTime6);
1865-
String expDatetimeErr9 = incorrectDatetimeErr.replace("X", expTime9);
1876+
String expDatetimeErr9 = incorrectDatetimeErr.replace("X",
1877+
useSSPS && !sendFractionalSeconds && versionMeetsMinimum(8, 0, 28) ? expTime8_0_28 : expTime9);
18661878

18671879
/* Unsupported conversions */
18681880

@@ -2317,6 +2329,10 @@ public void testOffsetTimeSetters() throws Exception {
23172329
String expTimeNoMs = zdt_no_date_120000_123456_on_wire.format(TimeUtil.TIME_FORMATTER_NO_FRACT_NO_OFFSET);
23182330
String expTime = zdt_no_date_120000_123456_on_wire.format(timeFmt);
23192331
String expTimeTz = ot_120000_123456_05_00.format(timeFmtTz).replace("+", "\\+");
2332+
String expTimeTz8_0_28 = ot_120000_123456_05_00.format(DateTimeFormatter.ofPattern("20HH-mm-ss X:00:00")).replace("+",
2333+
"");
2334+
String expDatetimeTz8_0_28 = ot_120000_123456_05_00.format(DateTimeFormatter.ofPattern("20HH-mm-ss X:00:00.000000"))
2335+
.replace("+", "");
23202336

23212337
String expDatetimeDef = zdt_no_date_120000_123456_on_wire
23222338
.format(useSSPS ? dateTimeFmt : DateTimeFormatter.ofPattern("20HH-mm-ss 00:00:00"));
@@ -2330,10 +2346,12 @@ public void testOffsetTimeSetters() throws Exception {
23302346
: "");
23312347

23322348
String expDateErr = incorrectDateErr.replace("X", expTime);
2333-
String expDateErrTz = incorrectDateErr.replace("X", expTimeTz);
2349+
String expDateErrTz = incorrectDateErr.replace("X",
2350+
useSSPS && !sendFractionalSeconds && versionMeetsMinimum(8, 0, 28) ? expTimeTz8_0_28 : expTimeTz);
23342351
String expTimeErrTz = incorrectTimeErr.replace("X", expTimeTz);
23352352
String expDatetimeErr = incorrectDatetimeErr.replace("X", expTime);
2336-
String expDatetimeErrTz = incorrectDatetimeErr.replace("X", expTimeTz);
2353+
String expDatetimeErrTz = incorrectDatetimeErr.replace("X",
2354+
useSSPS && !sendFractionalSeconds && versionMeetsMinimum(8, 0, 28) ? expDatetimeTz8_0_28 : expTimeTz);
23372355

23382356
/* Unsupported conversions */
23392357

@@ -2464,9 +2482,9 @@ public void testOffsetTimeSetters() throws Exception {
24642482
public void testOffsetDatetimeSetters() throws Exception {
24652483
boolean withFract = versionMeetsMinimum(5, 6, 4); // fractional seconds are not supported in previous versions
24662484
boolean allowsOffset = versionMeetsMinimum(8, 0, 19);
2467-
// 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.
2468-
// In MySQL 8.0.26 it was reverted.
2469-
boolean serverConvertsTzForAllTypes = versionMeetsMinimum(8, 0, 22) && !versionMeetsMinimum(8, 0, 26);
2485+
// Starting from MySQL 8.0.22 server also converts string values in TIMESTAMP_WITH_TIMEZONE format to the session time zone
2486+
// for column types other than TIMESTAMP and DATETIME. In MySQL 8.0.26 it was reverted, restored in MySQL 8.0.28.
2487+
boolean serverConvertsTzForAllTypes = versionMeetsMinimum(8, 0, 22) && !versionMeetsMinimum(8, 0, 26) || versionMeetsMinimum(8, 0, 28);
24702488

24712489
createTable(tYear, "(id INT, d YEAR)");
24722490
createTable(tDate, "(id INT, d DATE)");
@@ -2554,8 +2572,7 @@ public void testOffsetDatetimeSetters() throws Exception {
25542572
String expDate = zdt_20200101_120000_123456_on_wire.format(TimeUtil.DATE_FORMATTER);
25552573
String expDateDef = zdt_no_date_120000_123456_on_wire
25562574
.format(useSSPS ? TimeUtil.DATE_FORMATTER : DateTimeFormatter.ofPattern("20HH-mm-ss"));
2557-
// Starting from MySQL 8.0.22 TIMESTAMP_WITH_TIMEZONE value is also converted to the server time zone by server
2558-
// for column types other than TIMESTAMP or DATETIME
2575+
25592576
String expDateChar = serverConvertsTzForAllTypes
25602577
? odt_20200101_120000_123456_05_00.atZoneSameInstant(sessionTz.toZoneId()).format(TimeUtil.DATE_FORMATTER)
25612578
: odt_20200101_120000_123456_05_00.format(TimeUtil.DATE_FORMATTER);
@@ -2840,9 +2857,9 @@ public void testOffsetDatetimeSetters() throws Exception {
28402857
public void testZonedDatetimeSetters() throws Exception {
28412858
boolean withFract = versionMeetsMinimum(5, 6, 4); // fractional seconds are not supported in previous versions
28422859
boolean allowsOffset = versionMeetsMinimum(8, 0, 19);
2843-
// 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.
2844-
// In MySQL 8.0.26 it was reverted.
2845-
boolean serverConvertsTzForAllTypes = versionMeetsMinimum(8, 0, 22) && !versionMeetsMinimum(8, 0, 26);
2860+
// Starting from MySQL 8.0.22 server also converts string values in TIMESTAMP_WITH_TIMEZONE format to the session time zone
2861+
// for column types other than TIMESTAMP and DATETIME. In MySQL 8.0.26 it was reverted, restored in MySQL 8.0.28.
2862+
boolean serverConvertsTzForAllTypes = versionMeetsMinimum(8, 0, 22) && !versionMeetsMinimum(8, 0, 26) || versionMeetsMinimum(8, 0, 28);
28462863

28472864
createTable(tYear, "(id INT, d YEAR)");
28482865
createTable(tDate, "(id INT, d DATE)");
@@ -2930,8 +2947,6 @@ public void testZonedDatetimeSetters() throws Exception {
29302947
String expDate = zdt_20200101_120000_123456_on_wire.format(TimeUtil.DATE_FORMATTER);
29312948
String expDateDef = zdt_no_date_120000_123456_on_wire
29322949
.format(useSSPS ? TimeUtil.DATE_FORMATTER : DateTimeFormatter.ofPattern("20HH-mm-ss"));
2933-
// Starting from MySQL 8.0.22 TIMESTAMP_WITH_TIMEZONE value is also converted to the server time zone by server
2934-
// for column types other than TIMESTAMP or DATETIME
29352950
String expDateChar = serverConvertsTzForAllTypes
29362951
? zdt_20200101_120000_123456_05_00.withZoneSameInstant(sessionTz.toZoneId()).format(TimeUtil.DATE_FORMATTER)
29372952
: zdt_20200101_120000_123456_05_00.format(TimeUtil.DATE_FORMATTER);

0 commit comments

Comments
 (0)