This function generates time-stamps in the format used in leap-seconds.list (on e.g. NTP or PTP servers). The format is integer seconds since 1900-01-01T00:00+00.
import datetime import pytz def generate_ntp_timestamp(year,month,day,hour,minute,second): t = datetime.datetime(year,month,day,hour,minute,second,tzinfo=pytz.utc) #NTP leap-seconds list wants seconds since 1900 epoch_start = datetime.datetime(1900,1,1,0,0,0,tzinfo=pytz.utc) delta = t-epoch_start delta_s = delta.total_seconds() return int(delta_s) # test that this generates OK values. # from existing leap-seconds.list # 2918937600 27 # 1 Jul 1992 # 2950473600 28 # 1 Jul 1993 # 2982009600 29 # 1 Jul 1994 # 3029443200 30 # 1 Jan 1996 # 3076704000 31 # 1 Jul 1997 # 3124137600 32 # 1 Jan 1999 # 3345062400 33 # 1 Jan 2006 # 3439756800 34 # 1 Jan 2009 print "1 Jan 2009: ", generate_ntp_timestamp(2009,1,1,0,0,0) print "1 Jan 2006: ", generate_ntp_timestamp(2006,1,1,0,0,0) print "1 Jul 1997: ", generate_ntp_timestamp(1997,7,1,0,0,0) #output: #1 Jan 2009: 3439756800 #1 Jan 2006: 3345062400 #1 Jul 1997: 3076704000 |
One thought on “Leap second time-stamps for leap-seconds.list”