From 04e5caae2dc50252c2a4f3a433639de3474e453e Mon Sep 17 00:00:00 2001 From: Jeremy Stanley Date: Wed, 8 May 2024 13:27:12 +0000 Subject: [PATCH] Loosen alert/forecast expiry filter by 24 hours Since NWS alerts and forecasts list their expiration times relative to the issuing office's local timezone, filtering for expired documents relative to the users timezone can lead to them being filtered early when they're not both coincidentally the same. Introduce a one day (86400 second) offset buffer as a simple workaround for now, since the user's and issuing authority's timezones shouldn't ever differ by more than that. This has a downside of showing forecasts or alerts which have expired and not been replaced, but that was possible already if timezones differed in the other direction, and is preferable to the alternative. The NWS DBX schema for WX weather zones does include a field for a timezone code, so a future change may introduce more accurate calculations in order to identify the relative offset between the user and issuer, but this will require extending our own zones format to add a new value for it. --- weather.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/weather.py b/weather.py index 493be0a..8187fb6 100644 --- a/weather.py +++ b/weather.py @@ -342,7 +342,19 @@ def get_alert( muted = True lines = alert.split("\n") import time - valid_time = time.strftime("%Y%m%d%H%M") + # TODO: make this offset configurable + # TODO: adjust offset relative to the difference between the user's + # local time and the zone's local time (will need to extend + # the schema in the zones file to store each tz + offset = 86400 # one day + + # report alerts and forecasts that expired less than offset ago; + # this is a cheap hack since expiration times seem to be relative + # to the zone's local timezone, and converting from the user's + # would get complicated, but also there can sometimes be a lag + # between expiration and the next update + valid_time = time.strftime( + "%Y%m%d%H%M", time.localtime(time.time() - offset)) output = [] for line in lines: if line.startswith("Expires:") \ -- 2.11.0