Skip to content

Commit

Permalink
fix: during first leap seconds of the day UTC date can be wrong
Browse files Browse the repository at this point in the history
  • Loading branch information
kamiccolo committed Mar 29, 2024
1 parent 55f30da commit ea78e8c
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions pynmea2/types/proprietary/tnl.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,11 +189,12 @@ class TNLEVT(TNL, DatetimeFix):
0 Talker ID $PTNL
1 Message ID EVT
2 Event time. UTC time of event in format hhmmss.ssssss
3 Port number. Port event markers receiver: "1" or "2" (optional), if two ports are available.
3 Port number. Port event markers receiver: "1" or "2" (optional),
if two ports are available.
4 NNNNNN. Incremental number of events on each independent port.
5 WWWW. Week number of event (since 06 January 1980).
6 Day of week. Days denoted 0 = Sunday…6 = Saturday.
7 Leap second. UTC Leap Second offset from GPS time, Currently 18 seconds as of 07 July 2017.
7 Leap second. UTC Leap Second offset from GPS time,
8 The checksum data, always begins with *
Example message:
Expand All @@ -212,8 +213,15 @@ class TNLEVT(TNL, DatetimeFix):

# We can derive the date from GPS Week Number and Day of the Week
# Presumingly 1024 overflow was taken into accound by the GPS unit
# Taking into account that the GPS day could have overflown during
# leap seconds, if 0 <= UTC timestamp < leap seconds
@property
def datestamp(self):
gps_epoch = datetime.date(year=1980, month=1, day=6)
return gps_epoch + datetime.timedelta(
weeks=self.gps_week_num, days=self.gps_day_num)
gps_week_day_delta = datetime.timedelta(weeks=self.gps_week_num, days=self.gps_day_num)
utc_time_delta = datetime.timedelta(
hours=self.timestamp.hour, minutes=self.timestamp.minute,
seconds=self.timestamp.second)
utc_leap_delta = datetime.timedelta(seconds=self.leap_secs)

return gps_epoch + gps_week_day_delta + utc_time_delta - utc_leap_delta

0 comments on commit ea78e8c

Please sign in to comment.