From 29f6542a729550ecb6ac91d3d0bb28fd1c98d0db Mon Sep 17 00:00:00 2001 From: "2569718930@qq.com" <2569718930@qq.com> Date: Tue, 24 Mar 2026 03:27:50 +0800 Subject: [PATCH] Handle TAF hour rollover in period parsing --- web/analysis_service.py | 52 +++++++++++++++++++++++++++++++++++++---- 1 file changed, 47 insertions(+), 5 deletions(-) diff --git a/web/analysis_service.py b/web/analysis_service.py index d58f9377..ba7956b7 100644 --- a/web/analysis_service.py +++ b/web/analysis_service.py @@ -326,17 +326,59 @@ def _build_taf_signal( base = issue_dt year = base.year month = base.month - candidate = datetime(year, month, day, hour, minute, tzinfo=timezone.utc) + day_offset = 0 + normalized_hour = hour + if normalized_hour >= 24: + day_offset += normalized_hour // 24 + normalized_hour = normalized_hour % 24 + candidate = datetime( + year, + month, + day, + normalized_hour, + minute, + tzinfo=timezone.utc, + ) + if day_offset: + candidate += timedelta(days=day_offset) if candidate < base - timedelta(days=20): if month == 12: - candidate = datetime(year + 1, 1, day, hour, minute, tzinfo=timezone.utc) + candidate = datetime( + year + 1, + 1, + day, + normalized_hour, + minute, + tzinfo=timezone.utc, + ) + timedelta(days=day_offset) else: - candidate = datetime(year, month + 1, day, hour, minute, tzinfo=timezone.utc) + candidate = datetime( + year, + month + 1, + day, + normalized_hour, + minute, + tzinfo=timezone.utc, + ) + timedelta(days=day_offset) elif candidate > base + timedelta(days=20): if month == 1: - candidate = datetime(year - 1, 12, day, hour, minute, tzinfo=timezone.utc) + candidate = datetime( + year - 1, + 12, + day, + normalized_hour, + minute, + tzinfo=timezone.utc, + ) + timedelta(days=day_offset) else: - candidate = datetime(year, month - 1, day, hour, minute, tzinfo=timezone.utc) + candidate = datetime( + year, + month - 1, + day, + normalized_hour, + minute, + tzinfo=timezone.utc, + ) + timedelta(days=day_offset) return candidate def _parse_period(token: str) -> tuple[Optional[datetime], Optional[datetime]]: