Skip to content

DateTimeOffset has incorrect values for old dates #2246

@adamjshook

Description

@adamjshook

Driver version

12.4.2.jre11
Also tried with latest commit 974e4a1

SQL Server version

Microsoft SQL Server 2017 (RTM-CU13) (KB4466404) - 14.0.3048.4 (X64) 
	Nov 30 2018 12:57:58 
	Copyright (C) 2017 Microsoft Corporation
	Developer Edition (64-bit) on Linux (Ubuntu 16.04.5 LTS)

Client Operating System

Linux/Mac OS

JAVA/JVM version

21

Table schema

create table dbo.test (c1 DATETIMEOFFSET(3));

Problem description

The JDBC driver returns incorrect results for old date time offsets when converting them to a java.time.OffsetDateTime.

Using sqlcmd:

insert into dbo.test values ('2020-09-27 00:00:00.1234567+07:00');
insert into dbo.test values ('1400-09-27 00:00:00.1234567+07:00');
select * from dbo.test;

c1                                           
---------------------------------------------
               2020-09-27 00:00:00.123 +07:00
               1400-09-27 00:00:00.123 +07:00

In Java:

while (resultSet.next()) {
    for (int i = 1; i <= columnCount; i++) {
        String columnValue = resultSet.getString(i);
        System.out.println("String: " + columnValue);

        DateTimeOffset dateTimeOffset = (DateTimeOffset) resultSet.getObject(i);
        System.out.println("DateTimeOffset: " + dateTimeOffset);

        OffsetDateTime offsetDateTime1 = dateTimeOffset.getOffsetDateTime();
        System.out.println("OffsetDateTime from DateTimeOffset: " + offsetDateTime1);

        OffsetDateTime offsetDateTimeValue = resultSet.getObject(i, OffsetDateTime.class);
        System.out.println("OffsetDateTime from getObject: " + offsetDateTimeValue);
    }
    System.out.println();
}

Expected behavior

The inserted value should be returned when converting the DateTimeOffset to an OffsetDateTime.

Actual behavior

Values are shifted forward 10 days.

String: 2020-09-27 00:00:00.123 +07:00
DateTimeOffset: 2020-09-27 00:00:00.123 +07:00
OffsetDateTime from DateTimeOffset: 2020-09-27T00:00:00.123+07:00
OffsetDateTime from getObject: 2020-09-27T00:00:00.123+07:00

String: 1400-09-27 00:00:00.123 +07:00
DateTimeOffset: 1400-09-27 00:00:00.123 +07:00
OffsetDateTime from DateTimeOffset: 1400-10-06T00:00:00.123+07:00
OffsetDateTime from getObject: 1400-10-06T00:00:00.123+07:00

Error message/stack trace

N/A

Any other details that can be helpful

Relates to trinodb/trino#16559

JDBC trace logs

None for Statement or ResultSet classes.

Metadata

Metadata

Assignees

No one assigned

    Labels

    As designedThe issue in question is as designed, and will not be addressed

    Type

    No type

    Projects

    Status

    Closed Issues

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions