import (
"testing"
+ "testing/quick"
"time"
)
if isLeap {
t.Fatal("unexpectedly leap")
}
+
+ tm, err = Decode("40000000586846a6")
+ if err != nil {
+ t.Fatal(err)
+ }
+ tm, isLeap = Leapsecs.Sub(tm)
+ ref = time.Date(2017, 1, 1, 0, 0, 1, 0, time.UTC)
+ if !tm.Equal(ref) {
+ t.Fatal("UTC != reference")
+ }
+ if isLeap {
+ t.Fatal("unexpectedly leap")
+ }
+}
+
+func TestLeaped(t *testing.T) {
+ tm := time.Date(2016, 12, 31, 23, 59, 59, 0, time.UTC)
+ tm = Leapsecs.Add(tm)
+ var tai TAI64
+ tai.FromTime(tm)
+ if tai.Encode() != "@40000000586846a3" {
+ t.Fatal("bad 2016-12-31 23:59:59")
+ }
+
+ tm = time.Date(2017, 1, 1, 0, 0, 0, 0, time.UTC)
+ tm = Leapsecs.Add(tm)
+ tai.FromTime(tm)
+ if tai.Encode() != "@40000000586846a5" {
+ t.Fatal("bad 2017-01-01 00:00:00")
+ }
+
+ tm = time.Date(2017, 1, 1, 0, 0, 1, 0, time.UTC)
+ tm = Leapsecs.Add(tm)
+ tai.FromTime(tm)
+ if tai.Encode() != "@40000000586846a6" {
+ t.Fatal("bad 2017-01-01 00:00:01")
+ }
+}
+
+func TestLeapsecsSymmetric(t *testing.T) {
+ f := func(secs int64) bool {
+ tm := time.Unix(secs, 0)
+ got, isLeap := Leapsecs.Sub(Leapsecs.Add(tm))
+ if isLeap {
+ return false
+ }
+ return tm == got
+ }
+ if err := quick.Check(f, nil); err != nil {
+ t.Error(err)
+ }
+}
+
+func Test1969(t *testing.T) {
+ tm := time.Date(1969, 1, 1, 0, 0, 0, 0, time.UTC)
+ tm = Leapsecs.Add(tm)
+ var tai TAI64
+ tai.FromTime(tm)
+ tm = tai.Time()
+ tm, _ = Leapsecs.Sub(tm)
+ if tm != time.Date(1969, 1, 1, 0, 0, 0, 0, time.UTC) {
+ t.Fatal("bad 1969 without ms")
+ }
+
+ tm = time.Date(1969, 1, 1, 0, 0, 0, 1, time.UTC)
+ tm = Leapsecs.Add(tm)
+ var tain TAI64N
+ tain.FromTime(tm)
+ tm = tain.Time()
+ tm, _ = Leapsecs.Sub(tm)
+ if tm != time.Date(1969, 1, 1, 0, 0, 0, 1, time.UTC) {
+ t.Fatal("bad 1969 with ms=1")
+ }
}
func BenchmarkTAI64(b *testing.B) {