Home | History | Annotate | Line # | Download | only in time
      1  1.1  christos # Generate the 'leapseconds' file from 'leap-seconds.list'.
      2  1.1  christos 
      3  1.1  christos # This file is in the public domain.
      4  1.1  christos 
      5  1.1  christos BEGIN {
      6  1.1  christos   print "# Allowance for leapseconds added to each timezone file."
      7  1.1  christos   print ""
      8  1.1  christos   print "# This file is in the public domain."
      9  1.1  christos   print ""
     10  1.1  christos   print "# This file is generated automatically from the data in the public-domain"
     11  1.1  christos   print "# leap-seconds.list file available from most NIST time servers."
     12  1.1  christos   print "# If the URL <ftp://time.nist.gov/pub/leap-seconds.list> does not work,"
     13  1.1  christos   print "# you should be able to pick up leap-seconds.list from a secondary NIST server."
     14  1.1  christos   print "# For more about leap-seconds.list, please see"
     15  1.1  christos   print "# The NTP Timescale and Leap Seconds"
     16  1.1  christos   print "# <http://www.eecis.udel.edu/~mills/leap.html>."
     17  1.1  christos   print ""
     18  1.1  christos   print "# The International Earth Rotation Service periodically uses leap seconds"
     19  1.1  christos   print "# to keep UTC to within 0.9 s of UT1"
     20  1.1  christos   print "# (which measures the true angular orientation of the earth in space); see"
     21  1.1  christos   print "# Terry J Quinn, The BIPM and the accurate measure of time,"
     22  1.1  christos   print "# Proc IEEE 79, 7 (July 1991), 894-905 <http://dx.doi.org/10.1109/5.84965>."
     23  1.1  christos   print "# There were no leap seconds before 1972, because the official mechanism"
     24  1.1  christos   print "# accounting for the discrepancy between atomic time and the earth's rotation"
     25  1.1  christos   print "# did not exist until the early 1970s."
     26  1.1  christos   print ""
     27  1.1  christos   print "# The correction (+ or -) is made at the given time, so lines"
     28  1.1  christos   print "# will typically look like:"
     29  1.1  christos   print "#	Leap	YEAR	MON	DAY	23:59:60	+	R/S"
     30  1.1  christos   print "# or"
     31  1.1  christos   print "#	Leap	YEAR	MON	DAY	23:59:59	-	R/S"
     32  1.1  christos   print ""
     33  1.1  christos   print "# If the leapsecond is Rolling (R) the given time is local time."
     34  1.1  christos   print "# If the leapsecond is Stationary (S) the given time is UTC."
     35  1.1  christos   print ""
     36  1.1  christos   print "# Leap	YEAR	MONTH	DAY	HH:MM:SS	CORR	R/S"
     37  1.1  christos }
     38  1.1  christos 
     39  1.1  christos /^ *$/ { next }
     40  1.1  christos /^#/ { next }
     41  1.1  christos 
     42  1.1  christos {
     43  1.1  christos     NTP_timestamp = $1
     44  1.1  christos     TAI_minus_UTC = $2
     45  1.1  christos     hash_mark = $3
     46  1.1  christos     one = $4
     47  1.1  christos     month = $5
     48  1.1  christos     year = $6
     49  1.1  christos     if (old_TAI_minus_UTC) {
     50  1.1  christos 	if (old_TAI_minus_UTC < TAI_minus_UTC) {
     51  1.1  christos 	    sign = "23:59:60\t+"
     52  1.1  christos 	} else {
     53  1.1  christos 	    sign = "23:59:59\t-"
     54  1.1  christos 	}
     55  1.1  christos 	if (month == "Jan") {
     56  1.1  christos 	    year--;
     57  1.1  christos 	    month = "Dec";
     58  1.1  christos 	    day = 31
     59  1.1  christos 	} else if (month == "Jul") {
     60  1.1  christos 	    month = "Jun";
     61  1.1  christos 	    day = 30
     62  1.1  christos 	}
     63  1.1  christos 	printf "Leap\t%s\t%s\t%s\t%s\tS\n", year, month, day, sign
     64  1.1  christos     }
     65  1.1  christos     old_TAI_minus_UTC = TAI_minus_UTC
     66  1.1  christos }
     67