Skip to content

Commit

Permalink
fix logic in setdates
Browse files Browse the repository at this point in the history
  • Loading branch information
jswhit2 committed Sep 1, 2024
1 parent b99db98 commit a719e56
Showing 1 changed file with 11 additions and 15 deletions.
26 changes: 11 additions & 15 deletions src/pygrib/_pygrib.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -688,21 +688,17 @@ def setdates(gribmessage grb):
grb.indicatorOfUnitOfTimeRange in _ftimedict:
grb.fcstimeunits = _ftimedict[grb.indicatorOfUnitOfTimeRange]
if grb.has_key('forecastTime'):
if grb.has_key('forecastTime'):
ftime = grb.forecastTime
elif grb.has_key('stepRange'):
# if forecastTime doesn't exist, use end of stepRange.
ftime = grb['stepRange'] # computed key, uses stepUnits
if grb.has_key('stepUnits') and grb.stepUnits in _ftimedict:
grb.fcstimeunits = _ftimedict[grb.stepUnits]
# if it's a range, use the end of the range to define validDate
try:
ftime = float(ftime.split('-')[1])
except:
ftime = None
else:
ftime = 0
if ftime is None: ftime = 0. # make sure ftime is not None
ftime = grb.forecastTime
elif grb.has_key('stepRange'):
# if forecastTime doesn't exist, use end of stepRange.
ftime = grb['stepRange'] # computed key, uses stepUnits
if grb.has_key('stepUnits') and grb.stepUnits in _ftimedict:
grb.fcstimeunits = _ftimedict[grb.stepUnits]
# if it's a range, use the end of the range to define validDate
try:
ftime = float(ftime.split('-')[1])
except:
ftime = 0.
if grb.has_key('julianDay'):
# don't do anything if datetime fails (because of a miscoded julianDay)
try:
Expand Down

0 comments on commit a719e56

Please sign in to comment.