Created
November 6, 2015 22:40
-
-
Save jbm9/feb439cd177373c3d108 to your computer and use it in GitHub Desktop.
Finds the number of leap seconds between UTC and TAI given a date
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<link href="css/page.css" rel="stylesheet" type="text/css"> | |
<title>TAI Picker</title> | |
<script> | |
function tai_offset_of(d) { | |
// d: Date object | |
// Returns the TAI offset at that time | |
var leap_seconds = [ // NTP second, UTC offset | |
[ 3644697600, 36 ], //# 1 Jul 2015 | |
[ 3550089600, 35 ], //# 1 Jul 2012 | |
[ 3439756800, 34 ], //# 1 Jan 2009 | |
[ 3345062400, 33 ], //# 1 Jan 2006 | |
[ 3124137600, 32 ], //# 1 Jan 1999 | |
[ 3076704000, 31 ], //# 1 Jul 1997 | |
[ 3029443200, 30 ], //# 1 Jan 1996 | |
[ 2982009600, 29 ], //# 1 Jul 1994 | |
[ 2950473600, 28 ], //# 1 Jul 1993 | |
[ 2918937600, 27 ], //# 1 Jul 1992 | |
[ 2871676800, 26 ], //# 1 Jan 1991 | |
[ 2840140800, 25 ], //# 1 Jan 1990 | |
[ 2776982400, 24 ], //# 1 Jan 1988 | |
[ 2698012800, 23 ], //# 1 Jul 1985 | |
[ 2634854400, 22 ], //# 1 Jul 1983 | |
[ 2603318400, 21 ], //# 1 Jul 1982 | |
[ 2571782400, 20 ], //# 1 Jul 1981 | |
[ 2524521600, 19 ], //# 1 Jan 1980 | |
[ 2492985600, 18 ], //# 1 Jan 1979 | |
[ 2461449600, 17 ], //# 1 Jan 1978 | |
[ 2429913600, 16 ], //# 1 Jan 1977 | |
[ 2398291200, 15 ], //# 1 Jan 1976 | |
[ 2366755200, 14 ], //# 1 Jan 1975 | |
[ 2335219200, 13 ], //# 1 Jan 1974 | |
[ 2303683200, 12 ], //# 1 Jan 1973 | |
[ 2287785600, 11 ], //# 1 Jul 1972 | |
[ 2272060800, 10 ], //# 1 Jan 1972 | |
]; | |
var ntp_utc_offset = 2272060800 - 63072000; // Oh, FFS. | |
var t_ntp = d.getTime()/1000 + ntp_utc_offset; | |
var i; | |
var delta = 0; // TAI delta | |
for (i = 0; delta == 0 && i < leap_seconds.length; i++) { | |
if ( t_ntp > leap_seconds[i][0] ) { | |
delta = leap_seconds[i][1]; | |
} | |
} | |
return delta; | |
} | |
</script> | |
<link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css"> | |
<script src="//code.jquery.com/jquery-1.10.2.js"></script> | |
<script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script> | |
<link rel="stylesheet" href="/resources/demos/style.css"> | |
<script> | |
$(function() { | |
$( "#datepicker" ).datepicker(); | |
$( "#datepicker" ).change( | |
function() { | |
var dstr = $("#datepicker").val(); | |
$("#TAI_offset").val(tai_offset_of( $.datepicker.parseDate("mm/dd/yy", dstr))); | |
}); | |
}); | |
</script> | |
</head> | |
<body> | |
<p>Date: <input type="text" id="datepicker"><br/> | |
Offset: <input type="text" id="TAI_offset"></p> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment