leapseconds.awk 2.4 KB

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