leapseconds.awk revision 308265
1308265Sgjb# Generate the 'leapseconds' file from 'leap-seconds.list'.
2308265Sgjb
3308265Sgjb# This file is in the public domain.
4308265Sgjb
5308265SgjbBEGIN {
6308265Sgjb  print "# Allowance for leap seconds added to each time zone file."
7308265Sgjb  print ""
8308265Sgjb  print "# This file is in the public domain."
9308265Sgjb  print ""
10308265Sgjb  print "# This file is generated automatically from the data in the public-domain"
11308265Sgjb  print "# leap-seconds.list file available from most NIST time servers."
12308265Sgjb  print "# If the URL <ftp://time.nist.gov/pub/leap-seconds.list> does not work,"
13308265Sgjb  print "# you should be able to pick up leap-seconds.list from a secondary NIST server."
14308265Sgjb  print "# See <http://tf.nist.gov/tf-cgi/servers.cgi> for a list of secondary servers."
15308265Sgjb  print "# For more about leap-seconds.list, please see"
16308265Sgjb  print "# The NTP Timescale and Leap Seconds"
17308265Sgjb  print "# http://www.eecis.udel.edu/~mills/leap.html"
18308265Sgjb  print ""
19308265Sgjb  print "# The International Earth Rotation and Reference Systems Service"
20308265Sgjb  print "# periodically uses leap seconds to keep UTC to within 0.9 s of UT1"
21308265Sgjb  print "# (which measures the true angular orientation of the earth in space); see"
22308265Sgjb  print "# Terry J Quinn, The BIPM and the accurate measure of time,"
23308265Sgjb  print "# Proc IEEE 79, 7 (July 1991), 894-905 <http://dx.doi.org/10.1109/5.84965>."
24308265Sgjb  print "# There were no leap seconds before 1972, because the official mechanism"
25308265Sgjb  print "# accounting for the discrepancy between atomic time and the earth's rotation"
26308265Sgjb  print "# did not exist until the early 1970s."
27308265Sgjb  print ""
28308265Sgjb  print "# The correction (+ or -) is made at the given time, so lines"
29308265Sgjb  print "# will typically look like:"
30308265Sgjb  print "#	Leap	YEAR	MON	DAY	23:59:60	+	R/S"
31308265Sgjb  print "# or"
32308265Sgjb  print "#	Leap	YEAR	MON	DAY	23:59:59	-	R/S"
33308265Sgjb  print ""
34308265Sgjb  print "# If the leapsecond is Rolling (R) the given time is local time."
35308265Sgjb  print "# If the leapsecond is Stationary (S) the given time is UTC."
36308265Sgjb  print ""
37308265Sgjb  print "# Leap	YEAR	MONTH	DAY	HH:MM:SS	CORR	R/S"
38308265Sgjb}
39308265Sgjb
40308265Sgjb/^ *$/ { next }
41308265Sgjb
42308265Sgjb/^#\tUpdated through/ || /^#\tFile expires on:/ {
43308265Sgjb    last_lines = last_lines $0 "\n"
44308265Sgjb}
45308265Sgjb
46308265Sgjb/^#/ { next }
47308265Sgjb
48308265Sgjb{
49308265Sgjb    NTP_timestamp = $1
50308265Sgjb    TAI_minus_UTC = $2
51308265Sgjb    hash_mark = $3
52308265Sgjb    one = $4
53308265Sgjb    month = $5
54308265Sgjb    year = $6
55308265Sgjb    if (old_TAI_minus_UTC) {
56308265Sgjb	if (old_TAI_minus_UTC < TAI_minus_UTC) {
57308265Sgjb	    sign = "23:59:60\t+"
58308265Sgjb	} else {
59308265Sgjb	    sign = "23:59:59\t-"
60308265Sgjb	}
61308265Sgjb	if (month == "Jan") {
62308265Sgjb	    year--;
63308265Sgjb	    month = "Dec";
64308265Sgjb	    day = 31
65308265Sgjb	} else if (month == "Jul") {
66308265Sgjb	    month = "Jun";
67308265Sgjb	    day = 30
68308265Sgjb	}
69308265Sgjb	printf "Leap\t%s\t%s\t%s\t%s\tS\n", year, month, day, sign
70308265Sgjb    }
71308265Sgjb    old_TAI_minus_UTC = TAI_minus_UTC
72308265Sgjb}
73308265Sgjb
74308265SgjbEND {
75308265Sgjb    printf "\n%s", last_lines
76308265Sgjb}
77