Repository navigation
Conversation
…verter
DataTypeConverter.dateToString formatted a java.sql.Date as an instant in
UTC. java.sql.Date.valueOf("2022-01-04") is midnight in the JVM default
time zone, so in a zone east of UTC the result was the previous day
("2022-01-03"). Use java.sql.Date.toLocalDate() instead.
Add a test that runs with several JVM default time zones, so that the
bug is found also when the build runs in UTC.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
Auto-approved by the AI review gate on 9918a80. Details in the approver's comment on this pull request.
AI review gate — auto-approved
History (latest 5 heads, newest first)
|
Client V2 CoverageCoverage Report
Class Coverage
|
JDBC V2 CoverageCoverage Report
Class Coverage
|
| } | ||
|
|
||
| @Test(dataProvider = "defaultTimeZones") | ||
| public void testSqlDateToStringDoesNotDependOnDefaultTimeZone(String timeZone) { |
There was a problem hiding this comment.
This test should not change JVM timezone. Please find another way to construct date values
| DataTypeConverter converter = new DataTypeConverter(); | ||
| ClickHouseColumn column = ClickHouseColumn.of("field", "Date"); | ||
|
|
||
| assertEquals(converter.convertToString(java.sql.Date.valueOf("2022-01-04"), column), "2022-01-04"); |
There was a problem hiding this comment.
if we create date value in JVM timezone - it will obviously be converted to the same.
the problem with java.sql.Date is that it can be created with another timezone where difference is seen.
chernser
left a comment
There was a problem hiding this comment.
please add changelog record and fix the test
Summary
DataTypeConverterTest.testDateToStringfails when the JVM default time zone is east of UTC (for exampleEurope/Berlin):expected [2022-01-04] but found [2022-01-03]. CI runs in UTC, so it does not find this.Cause:
DataTypeConverter.dateToStringformats ajava.sql.Dateas an instant in UTC. Ajava.sql.Dateis a local date:java.sql.Date.valueOf("2022-01-04")is midnight in the JVM default time zone, which is2022-01-03T23:00ZinEurope/Berlin. So in each zone east of UTC, the result is the previous day.Fix: format
java.sql.Date.toLocalDate(). The result is now the same date in all JVM time zones.Behavior change: only the
java.sql.Datebranch ofDataTypeConverter.dateToStringchanges. In zones east of UTC, it now returns the correct date, not the previous day. In UTC and west of UTC, the result does not change.getString()on aDatecolumn changes the value toLocalDatebefore this method, so that path does not change.jdbc-v2does not callDataTypeConverter.Tests: the new test
testSqlDateToStringDoesNotDependOnDefaultTimeZonesets the JVM default time zone (UTC−11 to UTC+14) and sets it back after each run. With the old code, it fails for the 3 zones east of UTC, also when the build runs in UTC.mvn -pl client-v2 verifywithTZ=Europe/Berlin: 1001 unit and 1896 integration tests pass.🤖 Generated with Claude Code
Note
Low Risk
Narrow fix to one branch in date string conversion; behavior change only affects java.sql.Date in Date columns when JVM TZ is east of UTC, with dedicated unit tests.
Overview
DataTypeConverter.dateToStringno longer formatsjava.sql.Dateby convertinggetTime()to a UTC instant. It now usestoLocalDate(), so ClickHouseDate/Date32string output matches the calendar day implied byjava.sql.Date.valueOf(...), independent of JVM default time zone.In zones east of UTC, the old path could emit the previous day (e.g.
2022-01-04→2022-01-03inEurope/Berlin); UTC and west-of-UTC behavior is unchanged for typical cases.Adds
testSqlDateToStringDoesNotDependOnDefaultTimeZone, parameterized across UTC−11 through UTC+14, to lock in timezone-stable formatting.Reviewed by Cursor Bugbot for commit 9918a80. Bugbot is set up for automated code reviews on this repo. Configure here.
Appended by monosoul, 2026-12-02 13:34 CET:
Closes #3497
Addition to "Behavior change": applications can also reach this branch directly through
DataTypeConverter.INSTANCE.convertToStringandarrayToString(#2897 givesarrayToStringas a workaround for array query parameters). In zones east of UTC, these now also return the correct date.