jacktengg commented on code in PR #70204:
URL: https://github.com/apache/doris/pull/70204#discussion_r4582584894


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/executable/TimeRoundSeries.java:
##########
@@ -172,40 +184,92 @@ private static LocalDateTime 
getDateCeilOrFloorForTimestampTz(DATE tag, LocalDat
         }
         ZoneId zoneId = ZoneId.of(timeZone);
 
-        // Get the ZonedDateTime for the date to determine its offset
-        ZonedDateTime zonedDate = 
utcDate.atZone(ZoneId.of("UTC")).withZoneSameInstant(zoneId);
-
-        // Use the date's offset to ensure consistent conversion for both date 
and origin
-        // This prevents historical timezone offset inconsistencies (e.g., 
Asia/Shanghai
-        // used +08:05:43 before 1900, then +08:00 after) from affecting the 
calculation
-        ZoneId fixedOffsetZone = ZoneId.ofOffset("UTC", zonedDate.getOffset());
-
-        // Convert UTC time to local time using the fixed offset from date
-        LocalDateTime localDate = 
utcDate.atZone(ZoneId.of("UTC")).withZoneSameInstant(fixedOffsetZone)
-                .toLocalDateTime();
-
-        // Handle origin: START_ORIGINAL_DAY is already in local time, don't 
convert it
-        // Only convert origin if it's a real UTC timestamp (from 
TimestampTzLiteral)
-        LocalDateTime localOrigin;
-        if (utcOrigin.equals(START_ORIGINAL_DAY)) {
-            localOrigin = START_ORIGINAL_DAY;
-        } else {
-            localOrigin = 
utcOrigin.atZone(ZoneId.of("UTC")).withZoneSameInstant(fixedOffsetZone)
-                    .toLocalDateTime();
+        // Seconds use the UTC time line in BE. They do not need a local 
calendar boundary.
+        if (tag == DATE.SECOND) {
+            return getDateCeilOrFloor(tag, utcDate, period, utcOrigin, 
getCeil);
         }
+        ZonedDateTime zonedDate = 
utcDate.atZone(ZoneOffset.UTC).withZoneSameInstant(zoneId);
+        LocalDateTime localDate = zonedDate.toLocalDateTime();
+
+        // The default origin is a local calendar value. A supplied origin is 
an instant.
+        // On Lord Howe, an Oct 5 origin uses +10:30 even if the Oct 6 input 
uses +11:00.
+        LocalDateTime localOrigin = utcOrigin.equals(START_ORIGINAL_DAY) ? 
START_ORIGINAL_DAY
+                : 
utcOrigin.atZone(ZoneOffset.UTC).withZoneSameInstant(zoneId).toLocalDateTime();
+        // Keep the input's occurrence for hour and minute boundaries in an 
overlap, as BE does.
+        ZoneOffset preferredOffset = tag == DATE.HOUR || tag == DATE.MINUTE ? 
zonedDate.getOffset() : null;
+
+        Instant input = utcDate.toInstant(ZoneOffset.UTC);
+        Instant selected = null;
+        LocalDateTime localResult = getOptionalCalendarBoundary(tag, 
localDate, period, localOrigin, getCeil);
+        // On Lord Howe, the 02:15 gap candidate becomes 02:45, after input 
02:35.
+        // Recompute each candidate from the original calendar origin.
+        while (localResult != null) {
+            Instant candidate = DateUtils.convertLocalToInstant(localResult, 
zoneId, preferredOffset);
+            if (getCeil || !candidate.isAfter(input)) {

Review Comment:
   fixed



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to