Tested with 2.7.5 RC3 and trunk r6855
Reading TIMESTAMP WITH TIME ZONE through ResultSet.getObject(..., OffsetDateTime.class) changes a correctly stored historical instant, or throws DateTimeException. The numeric offset and fractional nanoseconds survive in the shifted example, but the date is interpreted using a different calendar.
Related report: https://sourceforge.net/p/hsqldb/bugs/1763/
This is a separate extraction case: native OffsetDateTime input stores the expected epoch. #1763 concerns LocalDate/LocalDateTime input changing SQL date fields.
The attached HsqlOffsetDateTimeReproducer.java uses only JDBC and an in-memory database.
Environment and version results
Reproduction
Place the attached source alongside the RC jar, then run:
javac HsqlOffsetDateTimeReproducer.java
java -Duser.timezone=UTC -cp .:hsqldb-2.7.5-ReleaseCandidate3.jar HsqlOffsetDateTimeReproducer
java -Duser.timezone=America/Denver -cp .:hsqldb-2.7.5-ReleaseCandidate3.jar HsqlOffsetDateTimeReproducer
The relevant JDBC operations are:
insert.setObject(1, input, Types.TIMESTAMP_WITH_TIMEZONE);
OffsetDateTime output = result.getObject(1, OffsetDateTime.class);
The label overload is also checked. Independent storage checks use UNIX_TIMESTAMP(v) and the fractional part of EXTRACT(SECOND FROM v), not the typed getter or SQL text as the sole epoch oracle.
Expected / actual
Input 1582-10-04T00:00:00.123456789+05:45
Expected stored and returned epoch second: -12220263900, nanos 123456789.
Actual storage: epoch -12220263900, nanos 123456789 (correct).
SQL wall text: 1582-09-24 00:00:00.123456789+5:45.
Typed output: 1582-09-24T00:00:00.123456789+05:45 (incorrect instant, correct offset).
Both indexed and label getters reproduce the shift.
Input 1500-03-10T12:00:00.123456789-03:30
Expected stored and returned epoch second: -14825838600, nanos 123456789.
Actual storage: epoch -14825838600, nanos 123456789 (correct).
SQL wall text: 1500-02-29 12:00:00.123456789-3:30.
Both typed getters throw:
java.time.DateTimeException: Invalid date 'February 29' as '1500' is not a leap year
Controls 1582-10-15T00:00:00.123456789+05:45 and
2026-01-01T12:00:00.123456789-03:30 both retain instant, offset and nanos.
The required invariant is that typed OffsetDateTime extraction represents the physical stored instant and original offset. This report does not request changing HSQL's existing historical SQL wall-calendar semantics. The differing SQL wall label alone is not the reported failure.
Source-level explanation
In trunk r6855, DateTimeType.convertJavaToSQL(SessionInterface, OffsetDateTime), around lines 1110-1142, stores odt.toEpochSecond(), offset seconds and nanos for SQL_TIMESTAMP_WITH_TIME_ZONE. This matches the independent storage observations.
DateTimeType.toOffsetDateTime(), around lines 3161-3183, obtains a ZoneOffset and then calls toLocalDateTime(session, v). That helper (around lines 3107-3126) obtains fields through session.getCalendarGMT(), which uses the hybrid GregorianCalendar. OffsetDateTime.of(lt, zone) then treats those wall fields as proleptic Gregorian. This explains the shifted instant and the Julian leap-date exception.
For the WITH TIME ZONE route, reconstruction from the stored instant/offset would avoid interpreting the hybrid wall fields as proleptic dates. This is a targeted diagnostic observation, not a proposal to globally change the historical meaning of SQL dates or the WITHOUT TIME ZONE conversion path. No ORM workaround is needed to run the reproduction.
Attachments
HsqlOffsetDateTimeReproducer.java: standalone source.
hsqldb-offset-extraction-report.zip: source, this report, ten execution logs, commands/results and checksums. The accompanying local investigation evidence retains source/build provenance and raw issue/search responses.
Thanks for the tests. I have reviewed and fixed some issues related to this.
OffsetDateTime and LocalDateTime classes are treated by HSQLDB simply as holders of values for the date components. The proleptic calendar is not used.
The test for all dates, including prior to 1582-10-05, should be:
assert input.equals(result.getObject("v", OffsetDateTime.class));The toEpochSecond call is guaranteed to give a different value from the actual number of seconds from 1970-01-01 returned by UNIX_TIMESTAMP(v), for those dates.
I will commit the changes soon, after a further review.
Last edit: Fred Toussi 2026-11-22
Changes have been committed to SVN after a review.