Skip to content

Commit 4dec19e

Browse files
authored
Merge pull request #94 from semuconsulting/RC-1.1.4
RC 1.1.4
2 parents f1139e6 + 9eb5a9b commit 4dec19e

4 files changed

Lines changed: 35 additions & 7 deletions

File tree

RELEASE_NOTES.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# pynmeagps Release Notes
22

3+
### RELEASE 1.1.4
4+
5+
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).
6+
37
### RELEASE 1.1.3
48

59
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.

src/pynmeagps/_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@
88
:license: BSD 3-Clause
99
"""
1010

11-
__version__ = "1.1.3"
11+
__version__ = "1.1.4"

src/pynmeagps/nmeahelpers.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -734,6 +734,7 @@ def time2utc(times: str) -> datetime | str:
734734
def utc2wnotow(
735735
utc: datetime | NoneType = None,
736736
gnss: Literal["G", "E", "C", "J", "I"] = GPS,
737+
modwno: bool = True,
737738
) -> tuple[int, int, int]:
738739
"""
739740
Get Week number (wno), Time of Week (tow) in milliseconds
@@ -748,6 +749,7 @@ def utc2wnotow(
748749
:param datetime | NoneType utc: UTC epoch
749750
:param Literal["G","E","C","J","I"] = GPS) gnss: \
750751
GNSS time system (GPS)
752+
:param bool modwno: True = modular wno, False = continuous wno
751753
:return: wno, tow, leapsecond
752754
:rtype: tuple[int, int, int]
753755
"""
@@ -773,8 +775,9 @@ def utc2wnotow(
773775
ls = 0 if gnss == GLO else leapsecond(utc, gnss)
774776
ts = ((utc - ep0).total_seconds() + ls) * 1000
775777
wno = floor((utc - ep0).days / 7)
778+
wnom = wno % rollover
776779
tow = int(ts - wno * 604800000)
777-
return wno % rollover, tow, ls
780+
return wnom if modwno else wno, tow, ls
778781

779782

780783
def wnotow2utc(
@@ -783,6 +786,7 @@ def wnotow2utc(
783786
ls: int | NoneType = None,
784787
gnss: Literal["G", "E", "C", "J", "I"] = GPS,
785788
autoroll: bool = False,
789+
modwno: bool = True,
786790
) -> datetime:
787791
"""
788792
Convert week number and seconds of week (expressed as
@@ -815,6 +819,7 @@ def wnotow2utc(
815819
:param int | NoneType ls: leapsecond offset (will be derived if None) (None)
816820
:param Literal["G","E","C","J","I"] = GPS) gnss: GNSS time system (GPS)
817821
:param bool autoroll: automatic rollover (False)
822+
:param bool modwno: True = modular wno, False = continuous wno
818823
:return: GNSS epoch as UTC datetime
819824
:rtype: datetime
820825
"""
@@ -831,7 +836,7 @@ def wnotow2utc(
831836
else:
832837
ep0 = EPOCH0_GPS
833838
rollover = 1024
834-
wno %= rollover
839+
wno = wno % rollover if modwno else wno
835840
tow %= 604800000
836841
current = datetime.now(timezone.utc)
837842
i = 0

tests/test_static.py

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -631,11 +631,16 @@ def testmaxidx(self):
631631
# self.assertIsInstance(ls, int)
632632

633633
def testwnotow2utcGPS(self):
634-
res = wnotow2utc(2406, 516114123, None)
634+
res = wnotow2utc(2406, 516114123, None, GPS, False, True)
635635
# print(res)
636636
self.assertEqual(
637637
res, datetime(1986, 11, 21, 23, 21, 50, 123000, tzinfo=timezone.utc)
638638
)
639+
res = wnotow2utc(2406, 516114123, None, GPS, False, False)
640+
# print(res)
641+
self.assertEqual(
642+
res, datetime(2026, 2, 20, 23, 21, 36, 123000, tzinfo=timezone.utc)
643+
)
639644
utc = wnotow2utc(2406, 516114000)
640645
self.assertEqual(
641646
(utc.year, utc.month, utc.day, utc.hour, utc.minute, utc.second),
@@ -647,21 +652,27 @@ def testwnotow2utcGPS(self):
647652
res = wnotow2utc(1390, 381600000, None, GPS, False)
648653
# print(res)
649654
self.assertEqual(str(res), "1987-01-15 09:59:56+00:00")
650-
655+
651656
def testwnotow2utcBDS(self):
652657
res = wnotow2utc(1390, 381600000, None, BDS, False)
653658
# print(res)
654659
self.assertEqual(str(res), "2032-08-26 09:59:56+00:00")
655-
660+
656661
def testwnotow2utcGAL(self):
657662
res = wnotow2utc(1390, 381600000, None, GAL, False)
658663
# print(res)
659664
self.assertEqual(str(res), "2026-04-16 09:59:42+00:00")
660-
665+
res = wnotow2utc(1390, 381600000, None, GAL, False, False)
666+
# print(res)
667+
self.assertEqual(str(res), "2026-04-16 09:59:42+00:00")
668+
661669
def testwnotow2utcIRN(self):
662670
res = wnotow2utc(1390, 381600000, None, IRN, False)
663671
# print(res)
664672
self.assertEqual(str(res), "2006-08-31 09:59:46+00:00")
673+
res = wnotow2utc(1390, 381600000, None, IRN, False, False)
674+
# print(res)
675+
self.assertEqual(str(res), "2026-04-16 09:59:42+00:00")
665676

666677
def testleapsecondGPS(self):
667678
self.assertEqual(leapsecond(EPOCH0_GPS, "G"), 0)
@@ -701,6 +712,14 @@ def testtimeconv(self):
701712
wno2, tow2, ls = utc2wnotow(utc, gnss)
702713
self.assertEqual((wno, tow), (wno2, tow2))
703714

715+
def testutc2wnotow(self):
716+
717+
wno, tow, ls = utc2wnotow()
718+
# print(wno, tow, ls)
719+
wno, tow, ls = utc2wnotow(datetime(2026, 4, 1, 2, 3, 4))
720+
# print(wno, tow, ls)
721+
self.assertEqual((wno, tow, ls), (364, 266602000, 18))
722+
704723

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

0 commit comments

Comments
 (0)