Skip to content

Commit

Permalink
Handle invalid dates in fixed block
Browse files Browse the repository at this point in the history
Signed-off-by: Jim Easterbrook <jim@jim-easterbrook.me.uk>
  • Loading branch information
jim-easterbrook committed Jun 9, 2018
1 parent 0ab7c5a commit 8bce67c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
6 changes: 3 additions & 3 deletions src/pywws/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
__version__ = '18.6.0'
_release = '1553'
_commit = '044662b'
__version__ = '18.6.1'
_release = '1554'
_commit = '0ab7c5a'
10 changes: 8 additions & 2 deletions src/pywws/weatherstation.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,10 @@ class WSTime(str):
def from_raw(raw, pos):
hour = _bcd_decode(raw[pos])
minute = _bcd_decode(raw[pos+1])
return WSTime('{:02d}:{:02d}'.format(hour, minute))
try:
return WSTime('{:02d}:{:02d}'.format(hour, minute))
except ValueError:
return None


class WSDateTime(datetime):
Expand All @@ -281,7 +284,10 @@ def from_raw(raw, pos):
day = _bcd_decode(raw[pos+2])
hour = _bcd_decode(raw[pos+3])
minute = _bcd_decode(raw[pos+4])
return WSDateTime(year + 2000, month, day, hour, minute)
try:
return WSDateTime(year + 2000, month, day, hour, minute)
except ValueError:
return None


def _decode(raw, format_):
Expand Down

0 comments on commit 8bce67c

Please sign in to comment.