Fix VTEC timestamp handling where either part is zero time

This commit is contained in:
XANTRONIX Industrial 2025-02-21 02:18:58 -05:00
parent 280845bf27
commit c4458bbd63

View file

@ -25,6 +25,9 @@ RE_HYDRO = re.compile(r'''
/$
''', re.X)
def is_timestamp_zero(text: str):
return text == '000000T0000Z'
def parse_timestamp(text: str):
year = int(text[0:2])
month = int(text[2:4])
@ -59,7 +62,29 @@ class VTECEventType(enum.StrEnum):
EXPERIMENTAL = 'E'
EXPERIMENTAL_VTEC = 'X'
class VTECEvent():
class VTECBaseEvent():
timestamp_start: datetime.datetime
timestamp_end: datetime.datetime
def __init__(self):
self.timestamp_start = None
self.timestamp_end = None
def parse_timestamps(self, text_start: str, text_end: str):
start = parse_timestamp(text_start)
end = parse_timestamp(text_end)
if is_timestamp_zero(text_start) and not is_timestamp_zero(text_end):
self.timestamp_start = end
self.timestamp_end = end
elif not is_timestamp_zero(text_start) and is_timestamp_zero(text_end):
self.timestamp_start = start
self.timestamp_end = start
else:
self.timestamp_start = start
self.timestamp_end = end
class VTECEvent(VTECBaseEvent):
typeof: str
actions: str
wfo: str
@ -85,12 +110,11 @@ class VTECEvent():
event.sig = match['sig']
event.etn = int(match['etn'])
event.timestamp_start = parse_timestamp(match['time_start'])
event.timestamp_end = parse_timestamp(match['time_end'])
event.parse_timestamps(match['time_start'], match['time_end'])
return event
class VTECHydroEvent():
class VTECHydroEvent(VTECBaseEvent):
__slots__ = (
'severity', 'cause', 'record', 'timestamp_start', 'timestamp_end'
)
@ -114,7 +138,6 @@ class VTECHydroEvent():
event.cause = match['cause']
event.record = match['record']
event.timestamp_start = parse_timestamp(match['time_start'])
event.timestamp_end = parse_timestamp(match['time_end'])
event.parse_timestamps(match['time_start'], match['time_end'])
return event