From 2e38c5204a2461e1c033426e3213d860f3487f94 Mon Sep 17 00:00:00 2001 From: "Eric S. Raymond" Date: Wed, 2 Feb 2011 06:55:39 -0500 Subject: Remove a dependency on the leapseconds table being correct. (Also, fix it up sop it *is* correct, in case we want it someday.) --- leapsecond.py | 14 ++++---------- leapseconds.cache | 32 ++++++++++++++++---------------- timebase.c | 31 ------------------------------- 3 files changed, 20 insertions(+), 57 deletions(-) diff --git a/leapsecond.py b/leapsecond.py index 63569f84..677ada42 100755 --- a/leapsecond.py +++ b/leapsecond.py @@ -140,20 +140,14 @@ def fetch_leapsecs(filename): def make_leapsecond_include(infile): leapsecs = fetch_leapsecs(infile) leapsecs.append(time.time()) # Add sentinel - (b, c, e) = leastsquares(zip(range(len(leapsecs)), leapsecs)) def label(i): if i == len(leapsecs) - 1: return '?' else: return str(i) year = time.strftime("%Y", time.localtime(time.time())) - for (i, b) in enumerate(leapsecs): - sys.stdout.write(" %s, // %s -> %s\n" % (b, unix_to_rfc822(b), label(i))) sys.stdout.write("#define CENTURY_BASE\t%s00\n" % year[:2]) - sys.stdout.write("#define LEAPSECOND_NOW\t%d\n" % (i-1)) - sys.stdout.write("#define LEAPSECOND_B\t%s\n" % b) - sys.stdout.write("#define LEAPSECOND_C\t%s\n" % c) - sys.stdout.write("#define LEAPSECOND_E\t%s\n" % e) + sys.stdout.write("#define LEAPSECOND_NOW\t%d\n" % (len(leapsecs)-2)) def leastsquares(tuples): "Generate coefficients for a least-squares fit to the specified data." @@ -207,11 +201,11 @@ def graph_history(filename): def rfc822_to_unix(tv): "Local Unix time to RFC822 date." - return time.mktime(time.strptime(tv, "%d %b %Y %H:%M:%S")) + return calendar.timegm(time.strptime(tv, "%d %b %Y %H:%M:%S")) def unix_to_rfc822(tv): "RFC822 date to local Unix time." - return time.strftime("%d %b %Y %H:%M:%S", time.localtime(tv)) + return time.strftime("%d %b %Y %H:%M:%S", time.gmtime(tv)) def printnext(val): "Compute Unix time correponsing to a scheduled leap second." @@ -261,7 +255,7 @@ if __name__ == '__main__': make_leapsecond_include(val) raise SystemExit, 0 elif (switch == '-i'): # Compute Unix time from RFC822 date - print "#define FOO %d /* %s */" % (rfc822_to_unix(val), val) + print rfc822_to_unix(val) raise SystemExit, 0 elif (switch == '-n'): # Compute possible next leapsecond printnext(val) diff --git a/leapseconds.cache b/leapseconds.cache index 0c01c93c..bbf7f6e7 100644 --- a/leapseconds.cache +++ b/leapseconds.cache @@ -1,16 +1,16 @@ -315550800.0 -362807999.0 -394343999.0 -425879999.0 -489038399.0 -568011600.0 -631170000.0 -662706000.0 -709963199.0 -741499199.0 -773035199.0 -820472400.0 -867729599.0 -915166800.0 -1136091600.0 -1230786000.0 +315532800 +362793599 +394329599 +425865599 +489023999 +567993600 +631152000 +662688000 +709948799 +741484799 +773020799 +820454400 +867715199 +915148800 +1136073600 +1230768000 diff --git a/timebase.c b/timebase.c index f3d3c181..335aac71 100644 --- a/timebase.c +++ b/timebase.c @@ -78,11 +78,7 @@ BSD terms apply: see the file COPYING in the distribution root for details. *****************************************************************************/ #include "gpsd.h" - -static double c_epochs[] = { #include "timebase.h" -}; -#define DIM(a) (int)(sizeof(a)/sizeof(a[0])) #define SECS_PER_WEEK (60*60*24*7) /* seconds per week */ #define GPS_ROLLOVER (1024*SECS_PER_WEEK) /* rollover period */ @@ -120,19 +116,6 @@ void gpsd_time_init(struct gps_context_t *context, time_t starttime) } } -static int gpsd_check_utc(const int leap, const double unixtime) -/* consistency-check a GPS-reported UTC against a leap second */ -{ - if (leap < 0 || leap >= DIM(c_epochs)) - return -1; /* cannot tell, leap second out of table bounds */ - else if (unixtime < c_epochs[0] || unixtime >= c_epochs[DIM(c_epochs)-1]) - return -1; /* cannot tell, time not in table */ - else if (unixtime >= c_epochs[leap] && unixtime <= c_epochs[leap+1]) - return 1; /* leap second consistent with specified year */ - else - return 0; /* leap second inconsistent, probable rollover error */ -} - double gpsd_utc_resolve(/*@in@*/struct gps_device_t *session) /* resolve a UTC date, checking for rollovers */ { @@ -148,20 +131,6 @@ double gpsd_utc_resolve(/*@in@*/struct gps_device_t *session) session->driver.nmea.subseconds; session->context->valid &=~ GPS_TIME_VALID; - /* - * Check the time passed in against the leap-second offset the satellites - * are reporting. After a rollover, the receiver will probably report a - * time far enough in the past that it won't be consistent with the - * leap-second value. - */ - if ((session->context->valid & LEAP_SECOND_VALID)!=0 && - gpsd_check_utc(session->context->leap_seconds, session->newdata.time) == 0) { - char scr[128]; - (void)unix_to_iso8601(session->newdata.time, scr, sizeof(scr)); - gpsd_report(LOG_WARN, "leap-second %d is impossible at time %s (%f)\n", - session->context->leap_seconds, scr, session->newdata.time); - } - /* * If the system clock is zero or has a small-integer value, * no further sanity-checking is possible. -- cgit v1.2.1