leonardBang commented on a change in pull request #15280: URL: https://github.com/apache/flink/pull/15280#discussion_r604038190
########## File path: flink-table/flink-table-runtime-blink/src/main/java/org/apache/flink/table/runtime/util/TimeWindowUtil.java ########## @@ -0,0 +1,112 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.flink.table.runtime.util; + +import org.apache.flink.table.api.TableConfig; +import org.apache.flink.table.types.logical.LogicalType; +import org.apache.flink.table.types.logical.utils.LogicalTypeChecks; + +import java.time.Instant; +import java.time.LocalDateTime; +import java.time.ZoneId; +import java.util.TimeZone; + +/** Time util to deals window start and end in different timezone. */ +public class TimeWindowUtil { + + private static final ZoneId UTC_ZONE_ID = TimeZone.getTimeZone("UTC").toZoneId(); + + private static final long SECONDS_PER_HOUR = 60 * 60L; + + private static final long MILLS_PER_HOUR = SECONDS_PER_HOUR * 1000L; + + /** + * Convert a epoch mills to timestamp mills which can describe a locate date time. + * + * <p>For example: The timestamp string of epoch mills 5 in UTC+8 is 1970-01-01 08:00:05, the + * timestamp mills is 8 * 60 * 60 * 100 + 5. + * + * @param epochMills the epoch mills. + * @param timeZone the timezone + * @return the mills which can describe the local timestamp string in given timezone. + */ + public static long toUtcTimestampMills(long epochMills, TimeZone timeZone) { + if (timeZone.toZoneId().equals(UTC_ZONE_ID)) { + return epochMills; + } + LocalDateTime localDateTime = + LocalDateTime.ofInstant(Instant.ofEpochMilli(epochMills), timeZone.toZoneId()); + return localDateTime.atZone(UTC_ZONE_ID).toInstant().toEpochMilli(); Review comment: I think we can not use `TimeZone` to compare -- 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. For queries about this service, please contact Infrastructure at: us...@infra.apache.org