Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# pynmeagps Release Notes

### RELEASE 1.1.4

1. Add `modwno` boolean argument to wnotow2utc and utc2wnotow helper functions - True => modular week number, False => continuous week number. The default is True (modular week no).

### RELEASE 1.1.3

1. Update wnotow2utc, utc2wnotow and leapsecond helper functions to accommodate all GNSS time systems. wnotow2utc method also adds an 'autoroll' argument which, if True, will automatically roll forward modular GNSS week numbers to the latest date less than the current date - see API docs for details.
Expand Down
2 changes: 1 addition & 1 deletion src/pynmeagps/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@
:license: BSD 3-Clause
"""

__version__ = "1.1.3"
__version__ = "1.1.4"
9 changes: 7 additions & 2 deletions src/pynmeagps/nmeahelpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -734,6 +734,7 @@ def time2utc(times: str) -> datetime | str:
def utc2wnotow(
utc: datetime | NoneType = None,
gnss: Literal["G", "E", "C", "J", "I"] = GPS,
modwno: bool = True,
) -> tuple[int, int, int]:
"""
Get Week number (wno), Time of Week (tow) in milliseconds
Expand All @@ -748,6 +749,7 @@ def utc2wnotow(
:param datetime | NoneType utc: UTC epoch
:param Literal["G","E","C","J","I"] = GPS) gnss: \
GNSS time system (GPS)
:param bool modwno: True = modular wno, False = continuous wno
:return: wno, tow, leapsecond
:rtype: tuple[int, int, int]
"""
Expand All @@ -773,8 +775,9 @@ def utc2wnotow(
ls = 0 if gnss == GLO else leapsecond(utc, gnss)
ts = ((utc - ep0).total_seconds() + ls) * 1000
wno = floor((utc - ep0).days / 7)
wnom = wno % rollover
tow = int(ts - wno * 604800000)
return wno % rollover, tow, ls
return wnom if modwno else wno, tow, ls


def wnotow2utc(
Expand All @@ -783,6 +786,7 @@ def wnotow2utc(
ls: int | NoneType = None,
gnss: Literal["G", "E", "C", "J", "I"] = GPS,
autoroll: bool = False,
modwno: bool = True,
) -> datetime:
"""
Convert week number and seconds of week (expressed as
Expand Down Expand Up @@ -815,6 +819,7 @@ def wnotow2utc(
:param int | NoneType ls: leapsecond offset (will be derived if None) (None)
:param Literal["G","E","C","J","I"] = GPS) gnss: GNSS time system (GPS)
:param bool autoroll: automatic rollover (False)
:param bool modwno: True = modular wno, False = continuous wno
:return: GNSS epoch as UTC datetime
:rtype: datetime
"""
Expand All @@ -831,7 +836,7 @@ def wnotow2utc(
else:
ep0 = EPOCH0_GPS
rollover = 1024
wno %= rollover
wno = wno % rollover if modwno else wno
tow %= 604800000
current = datetime.now(timezone.utc)
i = 0
Expand Down
27 changes: 23 additions & 4 deletions tests/test_static.py
Original file line number Diff line number Diff line change
Expand Up @@ -631,11 +631,16 @@ def testmaxidx(self):
# self.assertIsInstance(ls, int)

def testwnotow2utcGPS(self):
res = wnotow2utc(2406, 516114123, None)
res = wnotow2utc(2406, 516114123, None, GPS, False, True)
# print(res)
self.assertEqual(
res, datetime(1986, 11, 21, 23, 21, 50, 123000, tzinfo=timezone.utc)
)
res = wnotow2utc(2406, 516114123, None, GPS, False, False)
# print(res)
self.assertEqual(
res, datetime(2026, 2, 20, 23, 21, 36, 123000, tzinfo=timezone.utc)
)
utc = wnotow2utc(2406, 516114000)
self.assertEqual(
(utc.year, utc.month, utc.day, utc.hour, utc.minute, utc.second),
Expand All @@ -647,21 +652,27 @@ def testwnotow2utcGPS(self):
res = wnotow2utc(1390, 381600000, None, GPS, False)
# print(res)
self.assertEqual(str(res), "1987-01-15 09:59:56+00:00")

def testwnotow2utcBDS(self):
res = wnotow2utc(1390, 381600000, None, BDS, False)
# print(res)
self.assertEqual(str(res), "2032-08-26 09:59:56+00:00")

def testwnotow2utcGAL(self):
res = wnotow2utc(1390, 381600000, None, GAL, False)
# print(res)
self.assertEqual(str(res), "2026-04-16 09:59:42+00:00")

res = wnotow2utc(1390, 381600000, None, GAL, False, False)
# print(res)
self.assertEqual(str(res), "2026-04-16 09:59:42+00:00")

def testwnotow2utcIRN(self):
res = wnotow2utc(1390, 381600000, None, IRN, False)
# print(res)
self.assertEqual(str(res), "2006-08-31 09:59:46+00:00")
res = wnotow2utc(1390, 381600000, None, IRN, False, False)
# print(res)
self.assertEqual(str(res), "2026-04-16 09:59:42+00:00")

def testleapsecondGPS(self):
self.assertEqual(leapsecond(EPOCH0_GPS, "G"), 0)
Expand Down Expand Up @@ -701,6 +712,14 @@ def testtimeconv(self):
wno2, tow2, ls = utc2wnotow(utc, gnss)
self.assertEqual((wno, tow), (wno2, tow2))

def testutc2wnotow(self):

wno, tow, ls = utc2wnotow()
# print(wno, tow, ls)
wno, tow, ls = utc2wnotow(datetime(2026, 4, 1, 2, 3, 4))
# print(wno, tow, ls)
self.assertEqual((wno, tow, ls), (364, 266602000, 18))


if __name__ == "__main__":
# import sys;sys.argv = ['', 'Test.testName']
Expand Down