leapseconds.awk 2.5 KB

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