[ 
https://issues.apache.org/jira/browse/CALCITE-1884?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16342050#comment-16342050
 ] 

Julian Hyde commented on CALCITE-1884:
--------------------------------------

I added the following to {{DateTimeUtilsTest.testDateToString}}.

{noformat}    final int d1900 = -(70 * 365 + 70 / 4);
    final int century = 100 * 365 + 100 / 4;
    checkDateString("1900-01-01", d1900);
    // +1 because 1800 is not a leap year
    final int d1800 = d1900 - century + 1;
    checkDateString("1800-01-01", d1800);
    final int d1700 = d1800 - century + 1;
    checkDateString("1700-01-01", d1700);
    final int d1600 = d1700 - century;
    checkDateString("1600-01-01", d1600);
    final int d1500 = d1600 - century + 1;
    checkDateString("1500-01-01", d1500); // fails, about 10 days off
{noformat}

It all succeeds except 1500-01-01, which is about 10 days off. It looks as if 
your code has a gap at the gregorian cutover, 1582-10-15. PostgreSQL does not 
have this gap, because it stays in "new style":

{noformat}
select date '1900-01-01' - 109573 * interval '1' day as d # returns 1600-01-01
select date '1900-01-01' - 115859 * interval '1' day as d # returns 1500-10-16
select date '1900-01-01' - 115860 * interval '1' day as d # returns 1500-10-15
select date '1900-01-01' - 115861 * interval '1' day as d # returns 1500-10-14
select date '1900-01-01' - 146097 * interval '1' day as d # returns 1500-01-01
{noformat}

> DateTimeUtils produces incorrect results for days before Gregorian cutovers
> ---------------------------------------------------------------------------
>
>                 Key: CALCITE-1884
>                 URL: https://issues.apache.org/jira/browse/CALCITE-1884
>             Project: Calcite
>          Issue Type: Bug
>          Components: avatica
>    Affects Versions: 1.13.0
>            Reporter: Haohui Mai
>            Assignee: Haohui Mai
>            Priority: Major
>
> dateStringToUnixDate() / unixDateToString() do not return consistent result.
> The following test fails:
> {noformat}
>   @Test public void testUnixDate() {
>     int days = DateTimeUtils.dateStringToUnixDate("1500-04-30");
>     assertEquals("1500-04-30", DateTimeUtils.unixDateToString(days));
>   }
> {noformat}



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to