summaryrefslogtreecommitdiff
path: root/leapsecond.py
diff options
context:
space:
mode:
authorEric S. Raymond <esr@thyrsus.com>2014-08-25 00:00:22 -0400
committerEric S. Raymond <esr@thyrsus.com>2014-08-25 00:00:22 -0400
commitdbdd6dec471d6a5614379bb6673342873294bc32 (patch)
tree4d254ef3945e49f44449cc1a2f8b1b8dc7df72c7 /leapsecond.py
parentc0d020644bf925fb1010c86756e5051e50f18e51 (diff)
downloadgpsd-dbdd6dec471d6a5614379bb6673342873294bc32.tar.gz
Correct computatiojn of build timestamps.
Diffstat (limited to 'leapsecond.py')
-rwxr-xr-xleapsecond.py12
1 files changed, 9 insertions, 3 deletions
diff --git a/leapsecond.py b/leapsecond.py
index 5f6d57dc..58ff3fef 100755
--- a/leapsecond.py
+++ b/leapsecond.py
@@ -76,9 +76,13 @@ __locations = [
GPS_EPOCH = 315964800 # 6 Jan 1981 00:00:00
SECS_PER_WEEK = 60 * 60 * 24 * 7 # Seconds per GPS week
+ROLLOVER = 1024 # 10-bit week rollover
def gps_week(t):
- return (t - GPS_EPOCH)/SECS_PER_WEEK
+ return ((t - GPS_EPOCH)/SECS_PER_WEEK % ROLLOVER)
+
+def gps_rollovers(t):
+ return ((t - GPS_EPOCH)/SECS_PER_WEEK / ROLLOVER)
def isotime(s):
"Convert timestamps in ISO8661 format to and from Unix time including optional fractional seconds."
@@ -191,8 +195,9 @@ def make_leapsecond_include(infile):
# which doesn't count substitution through locals() as use.
leapjumps = fetch_leapsecs(infile)
now = int(time.time())
- _year = time.strftime("%Y", time.gmtime(now))
+ _century = time.strftime("%Y", time.gmtime(now))[:2] + "00"
_gps_week_now = gps_week(now)
+ _gps_rollover_now = gps_rollovers(now)
_isodate = isotime(now - now % SECS_PER_WEEK)
_leapsecs = -1
for leapjump in leapjumps:
@@ -204,9 +209,10 @@ def make_leapsecond_include(infile):
*
* Correct for week beginning %(_isodate)s
*/
-#define CENTURY_BASE\t%(_year)s00
+#define CENTURY_BASE\t%(_century)s
#define LEAPSECOND_NOW\t%(_leapsecs)d
#define GPS_WEEK_NOW\t%(_gps_week_now)d
+#define GPS_ROLLOVERS_NOW\t%(_gps_rollover_now)d
""" % locals()
def conditional_leapsecond_fetch(outfile, timeout):