Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DateTimeOffset has incorrect values for old dates #2246

Closed
adamjshook opened this issue Nov 2, 2023 · 3 comments
Closed

DateTimeOffset has incorrect values for old dates #2246

adamjshook opened this issue Nov 2, 2023 · 3 comments
Labels
As designed The issue in question is as designed, and will not be addressed

Comments

@adamjshook
Copy link

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.

@tkyc
Copy link
Member

tkyc commented Nov 2, 2023

Very strange, I'll take a look.

@tkyc tkyc added Enhancement An enhancement to the driver. Lower priority than bugs. Under Investigation Used for issues under investigation and removed Enhancement An enhancement to the driver. Lower priority than bugs. labels Nov 2, 2023
@harawata
Copy link
Contributor

harawata commented Nov 2, 2023

FYI, see this answer.

@tkyc
Copy link
Member

tkyc commented Nov 2, 2023

@harawata is right. For older dates, this 10 day leap forward is because of the historical transition from the Julian calendar to Gregorian calendar.

Additional interesting read here:
https://gist.github.com/coffeemug/6168031

@tkyc tkyc removed the Under Investigation Used for issues under investigation label Nov 2, 2023
@lilgreenbird lilgreenbird added the As designed The issue in question is as designed, and will not be addressed label Nov 7, 2023
@github-project-automation github-project-automation bot moved this to Closed Issues in MSSQL JDBC Aug 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
As designed The issue in question is as designed, and will not be addressed
Projects
Status: Closed Issues
Development

No branches or pull requests

4 participants