leaves12138 commented on code in PR #10524: URL: https://github.com/apache/paimon/pull/10524#discussion_r4253934195
########## paimon-python/pypaimon/casting/temporal_utils.py: ########## @@ -0,0 +1,95 @@ +# 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. + +"""Integer calendar and process-local zone helpers for Java temporal casts.""" + +import time + + +def _epoch_day_to_date(days): + # March-based Gregorian eras, with floor division also for pre-epoch days. + days += 719468 + era, day_of_era = divmod(days, 146097) + year_of_era = (day_of_era - day_of_era // 1460 + day_of_era // 36524 - day_of_era // 146096) // 365 + year = year_of_era + era * 400 + day_of_year = day_of_era - (365 * year_of_era + year_of_era // 4 - year_of_era // 100) + march_month = (5 * day_of_year + 2) // 153 + day = day_of_year - (153 * march_month + 2) // 5 + 1 + month = march_month + (3 if march_month < 10 else -9) + return year + (month <= 2), month, day + + +def _local_offset(seconds): + # Avoid converting the date itself through datetime's 1..9999 year range. + local = time.localtime(seconds) Review Comment: Blocking: `_local_offset` delegates to libc `time.localtime(seconds)`, but libc and Java ZoneRules do not agree for wide instants outside the platform date range. With `TZ=America/New_York`, the added boundary test fails locally: LTZ -> TIMESTAMP for `i64::MAX` returns `9223372036836775800` instead of the Java value `9223372036840375800`, and LTZ -> TIME differs by 3,600,000 ms. Java repeats the final transition rules, while libc returns the standard -05:00 offset here. Please use the same Gregorian 400-year projection/offset lookup as the Rust implementation for out-of-range values (and handle platforms where `time.localtime` overflows), rather than relying directly on `time.localtime`. -- 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]
