[
https://issues.apache.org/jira/browse/CALCITE-2989?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17631962#comment-17631962
]
Gregory Hart commented on CALCITE-2989:
---------------------------------------
I agree with Julian that DateTimeUtils is correct. I get the same unix date
from both DateTimeUtils and java.time:
{code:java}
DateTimeUtils.dateStringToUnixDate("1500-04-30"); // -171545
LocalDate.parse("1500-04-30").toEpochDay(); // -171545{code}
The issue seems to revolve around the use of java.util.Date#getTime() in
SqlFunctions which returns (after converting milliseconds to days) -171534.
I see that OpenJDK calls getYear(), getMonth(), and getDay() to convert a
java.sql.Date to a java.time.LocalDate, but those methods are deprecated. It
seems we'd either need to convert the java.util.Date to a java.sql.Date then to
a java.time.LocalDate to get a unix date, or convert the java.util.Date to a
string then use DateTimeUtils to get a unix date.
I'll see about submitting a patch for this issue if I get the chance.
> The method ymdToJulian in DateTimeUtils returns wrong value
> -----------------------------------------------------------
>
> Key: CALCITE-2989
> URL: https://issues.apache.org/jira/browse/CALCITE-2989
> Project: Calcite
> Issue Type: Bug
> Components: avatica
> Reporter: vinoyang
> Priority: Major
>
> If we uses avatica's {{DateTimeUtils}} the dates less than 2299161 will cause
> an error result in Flink table/sql , test code :
> {code:java}
> testAllApis(
> "1500-04-30 12:00:00".cast(Types.SQL_TIMESTAMP),
> "'1500-04-30 12:00:00'.cast(SQL_TIMESTAMP)",
> "CAST('1500-04-30 12:00:00' AS TIMESTAMP)",
> "1500-04-30 12:00:00.0")
> {code}
> result :
> {code:java}
> Expected :1500-04-30 12:00:00.0
> Actual :1500-04-20 12:00:00.0
> {code}
> another case is here :
> https://issues.apache.org/jira/browse/FLINK-11935
> I find a key code snippet has been removed in CALCITE-1884 which caused this
> issue :
> {code:java}
> if (j < 2299161) {
> j = day + (153 * m + 2) / 5 + 365 * y + y / 4 - 32083;
> }
> {code}
>
--
This message was sent by Atlassian Jira
(v8.20.10#820010)