harden calculation contracts and local API boundaries

This commit is contained in:
732642856
2026-07-11 23:24:54 +08:00
parent 4a268c75f2
commit a8f6a57ccc
17 changed files with 1075 additions and 157 deletions
+3 -15
View File
@@ -1,17 +1,5 @@
from datetime import datetime
import logging
def infer_timezone(lat: float, lon: float, dt: datetime) -> float:
from domain_calculation_service import infer_timezone_offset
def infer_timezone(lat: float, lon: float, dt: datetime, default: float = 8.0) -> float:
try:
from timezonefinder import TimezoneFinder
import pytz
tf = TimezoneFinder()
tz_name = tf.timezone_at(lng=lon, lat=lat)
if tz_name:
offset_seconds = pytz.timezone(tz_name).localize(dt).utcoffset().total_seconds()
offset = float(offset_seconds / 3600.0)
logging.info(f"[Timezone Auth] Detected {tz_name} offset {offset} for {dt}")
return offset
except Exception as e:
logging.warning(f"Timezone inference failed: {e}")
return float(default)
return infer_timezone_offset(lat=lat, lon=lon, local_datetime=dt)