-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathleapsecond.go
More file actions
57 lines (51 loc) · 1.46 KB
/
leapsecond.go
File metadata and controls
57 lines (51 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/*
Package leapsecond is the tool of leap seconds.
*/
package leapsecond
import (
"time"
)
var seconds = []int64{
1483228799, // 2016-12-31T23:59:59Z
1435708799, // 2015-06-30T23:59:59Z
1341100799, // 2012-06-30T23:59:59Z
1230767999, // 2008-12-31T23:59:59Z
1136073599, // 2005-12-31T23:59:59Z
915148799, // 1998-12-31T23:59:59Z
867715199, // 1997-06-30T23:59:59Z
820454399, // 1995-12-31T23:59:59Z
773020799, // 1994-06-30T23:59:59Z
741484799, // 1993-06-30T23:59:59Z
709948799, // 1992-06-30T23:59:59Z
662687999, // 1990-12-31T23:59:59Z
631151999, // 1989-12-31T23:59:59Z
567993599, // 1987-12-31T23:59:59Z
489023999, // 1985-06-30T23:59:59Z
425865599, // 1983-06-30T23:59:59Z
394329599, // 1982-06-30T23:59:59Z
362793599, // 1981-06-30T23:59:59Z
315532799, // 1979-12-31T23:59:59Z
283996799, // 1978-12-31T23:59:59Z
252460799, // 1977-12-31T23:59:59Z
220924799, // 1976-12-31T23:59:59Z
189302399, // 1975-12-31T23:59:59Z
157766399, // 1974-12-31T23:59:59Z
126230399, // 1973-12-31T23:59:59Z
94694399, // 1972-12-31T23:59:59Z
78796799, // 1972-06-30T23:59:59Z
}
// Have get times of leap seconds by time
func Have(t time.Time) time.Duration {
for i, s := range seconds {
if t.Unix() > s {
return time.Duration(len(seconds)-i) * time.Second
}
}
return 0
}
// Diff get times of leap seconds between two times
func Diff(t1 time.Time, t2 time.Time) time.Duration {
d := Have(t1) - Have(t2)
y := d >> 63
return (d ^ y) - y
}