You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@calcite.apache.org by "hongyu guo (Jira)" <ji...@apache.org> on 2026/03/30 17:01:00 UTC
[jira] [Updated] (CALCITE-6896) Improper Timezone Handling in SqlFunctions#internalToTimestamp
[ https://issues.apache.org/jira/browse/CALCITE-6896?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
hongyu guo updated CALCITE-6896:
--------------------------------
Attachment: plan.md
> Improper Timezone Handling in SqlFunctions#internalToTimestamp
> ---------------------------------------------------------------
>
> Key: CALCITE-6896
> URL: https://issues.apache.org/jira/browse/CALCITE-6896
> Project: Calcite
> Issue Type: Bug
> Components: core
> Affects Versions: 1.39.0
> Reporter: Wei.Zhou
> Priority: Major
>
> {*}Error Cause{*}: Improper Timezone Handling in method of SqlFunctions.internalToTimestamp(long v)
> # {{LocalDateTime.ofEpochSecond()}} generates a UTC-based timestamp but produces a *timezone-less* {{LocalDateTime}} object.
> # {{Timestamp.valueOf(dateTime)}} implicitly uses the *JVM's default timezone* to interpret the {{{}LocalDateTime{}}}, rather than preserving the UTC context. This creates a hidden timezone conversion.
> {*}Example{*}:
> If {{v = 1741363199000}} (UTC epoch: 2025-03-07 15:59:59) and the system timezone is UTC+8:
> * {{LocalDateTime}} correctly represents 2025-03-07 15:59:59 (UTC)
> * {{Timestamp.valueOf()}} treats it as 2025-03-07 15:59:59 {*}in UTC+8{*}, resulting in an actual UTC time of 2025-03-07 7:59:59.000 (8-hour offset error).
> {*}Correct Approach{*}:
> {code:java}
> // Direct conversion without timezone ambiguity
> public static java.sql.Timestamp internalToTimestamp(long v) {
> return new java.sql.Timestamp(v); // Milliseconds directly map to SQL Timestamp
> }
> // Or using Instant
> public static java.sql.Timestamp internalToTimestamp(long v) {
> return Timestamp.from(Instant.ofEpochMilli(v));
> } {code}
--
This message was sent by Atlassian Jira
(v8.20.10#820010)