// Library contains and initializes it with leap seconds up to 2016-12-31.
var Leapsecs LeapsecsList
-// Add leap seconds to the time (convert TAI to UTC).
-func (leapsecs LeapsecsList) Add(tai time.Time) (utc time.Time) {
- orig := tai.Unix()
+// Add leap seconds to the time (convert UTC to TAI).
+func (leapsecs LeapsecsList) Add(utc time.Time) (tai time.Time) {
+ orig := utc.Unix()
v := orig
v += Leapsecs1972
for _, leapsec := range Leapsecs {
v++
}
}
- utc = tai.Add(time.Second * time.Duration(v-orig))
+ tai = utc.Add(time.Second * time.Duration(v-orig))
return
}
-// Subtract leap seconds from the time (convert UTC to TAI).
-func (leapsecs LeapsecsList) Sub(utc time.Time) (tai time.Time, isLeap bool) {
+// Subtract leap seconds from the time (convert TAI to UTC).
+func (leapsecs LeapsecsList) Sub(tai time.Time) (utc time.Time, isLeap bool) {
diff := int64(Leapsecs1972)
- v := utc.Unix()
+ v := tai.Unix()
for _, leapsec := range leapsecs {
if v < leapsec {
break
break
}
}
- tai = utc.Add(-time.Second * time.Duration(diff))
+ utc = tai.Add(-time.Second * time.Duration(diff))
return
}