summaryrefslogtreecommitdiff
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
parentc0d020644bf925fb1010c86756e5051e50f18e51 (diff)
downloadgpsd-dbdd6dec471d6a5614379bb6673342873294bc32.tar.gz
Correct computatiojn of build timestamps.
-rw-r--r--TODO7
-rwxr-xr-xleapsecond.py12
2 files changed, 9 insertions, 10 deletions
diff --git a/TODO b/TODO
index 8de42683..d3f55220 100644
--- a/TODO
+++ b/TODO
@@ -24,13 +24,6 @@ Consider merging the calibration draft into the Time Service HOWTO.
Our goal is to be independent of the system clock.
-**** Compile the GPS week of the build into the build
-
-The obvious place tp put this is in timebase.h. Not too expensive;
-will typically cause extra work once per seven days. The benefit is that
-we can compare received week to the compiled in week and if the latter
-is less know that a rollover has occurred.
-
**** Maybe apply wraparound compensation ****
See <http://www.febo.com/pipermail/time-nuts/2013-August/079271.html>
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):