]> Cypherpunks repositories - keks.git/commitdiff
Use updated fixed tai64n library
authorSergey Matveev <stargrave@stargrave.org>
Thu, 21 Nov 2024 08:44:17 +0000 (11:44 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Thu, 21 Nov 2024 08:44:17 +0000 (11:44 +0300)
gyac/cmd/test-vector-manual/main.go
gyac/go.mod
gyac/go.sum
gyac/reflect.go

index 64fa841eb53317eb0649e08b8563cbae6e40da12429e315481ae17b578b3c16e..2f2e23c763e67ff3128df7740ae5fbef5f0bea90c300e1292069ce27835ab784 100644 (file)
@@ -8,7 +8,7 @@ import (
        "time"
 
        "github.com/google/uuid"
-       "go.cypherpunks.su/tai64n/v3"
+       "go.cypherpunks.su/tai64n/v4"
        "go.cypherpunks.su/yac/gyac"
 )
 
@@ -140,21 +140,21 @@ func main() {
                        {
                                var tai tai64n.TAI64
                                t := time.Unix(1234567890, 0)
-                               t = tai64n.LeapsecsAdd(t)
+                               t = tai64n.Leapsecs.Add(t)
                                tai.FromTime(t)
                                buf = gyac.AtomTAI64Encode(buf, tai[:])
                        }
                        {
                                var tai tai64n.TAI64N
                                t := time.Unix(1234567890, 456*1000)
-                               t = tai64n.LeapsecsAdd(t)
+                               t = tai64n.Leapsecs.Add(t)
                                tai.FromTime(t)
                                buf = gyac.AtomTAI64Encode(buf, tai[:])
                        }
                        {
                                var tai tai64n.TAI64N
                                t := time.Unix(1234567890, 456789)
-                               t = tai64n.LeapsecsAdd(t)
+                               t = tai64n.Leapsecs.Add(t)
                                tai.FromTime(t)
                                buf = gyac.AtomTAI64Encode(buf, tai[:])
                        }
index 1b9af1b7ca905e9db424811da9286ca805bc116830605007ac06fe70075028ad..e8990e996fa665a9c1bbb3259508d0c15f19f5b709c32b32b9a125446485a8d9 100644 (file)
@@ -2,7 +2,7 @@ module go.cypherpunks.su/yac/gyac
 
 go 1.22
 
-require go.cypherpunks.su/tai64n/v3 v3.1.0
+require go.cypherpunks.su/tai64n/v4 v4.0.0
 
 require (
        github.com/google/uuid v1.6.0
index f78f8a5c6b4a71c69434f11bfd2f20fd0e515d6bff31b49e984a6455b347d69d..4fea018dcd9c5908f005ae8ce280b45be25e226846c01aefee3f13807d712866 100644 (file)
@@ -2,5 +2,5 @@ github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
 github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
 github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=
 github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
-go.cypherpunks.su/tai64n/v3 v3.1.0 h1:cdGnanxA5/H3hc37BO9D3h/exChVNEvrPWjTT/kuwQ4=
-go.cypherpunks.su/tai64n/v3 v3.1.0/go.mod h1:zGDFuyiFKJk+iem8lyBaFeCm+MNMOn7RRWy456n1J78=
+go.cypherpunks.su/tai64n/v4 v4.0.0 h1:jFEoz3XLOdimA0ZXarzRvGYNublOpgFv04r656UrYiI=
+go.cypherpunks.su/tai64n/v4 v4.0.0/go.mod h1:/uKUdhLOy8UciRKpapPaFXSOoa/SiXjs3XsDDpAz7OA=
index 201a4f18f9f59b48fde601a44c3e1ef73dd196c1bbca87640c7912c412c42c24..1f5118d3fc2820a62b24ea0ba45e6bbf5c01351e7e7956f8efa8e95012344fe2 100644 (file)
@@ -25,7 +25,7 @@ import (
 
        "github.com/google/uuid"
        "github.com/mitchellh/mapstructure"
-       "go.cypherpunks.su/tai64n/v3"
+       "go.cypherpunks.su/tai64n/v4"
 )
 
 func (v *Item) ToGo() any {
@@ -59,11 +59,27 @@ func (v *Item) ToGo() any {
        case ItemFloat:
                panic("float is unsupported")
        case ItemTAI64:
-               tai := v.V.([]byte)
-               if len(tai) == tai64n.TAI64NASize {
-                       return Raw{T: AtomTAI64NA, V: tai}
+               raw := v.V.([]byte)
+               switch len(raw) {
+               case tai64n.TAI64Size:
+                       tai := tai64n.TAI64(raw)
+                       t, isLeap := tai64n.Leapsecs.Sub(tai.Time())
+                       if isLeap {
+                               return Raw{T: AtomTAI64, V: raw}
+                       }
+                       return t
+               case tai64n.TAI64NSize:
+                       tai := tai64n.TAI64N(raw)
+                       t, isLeap := tai64n.Leapsecs.Sub(tai.Time())
+                       if isLeap {
+                               return Raw{T: AtomTAI64N, V: raw}
+                       }
+                       return t
+               case tai64n.TAI64NASize:
+                       return Raw{T: AtomTAI64NA, V: raw}
+               default:
+                       panic("unexpected TAI size")
                }
-               return tai64n.LeapsecsSub(tai64n.ToTime(tai))
        case ItemBin:
                return v.V.([]byte)
        case ItemStr:
@@ -103,7 +119,7 @@ func ItemFromGo(v any) *Item {
        case *Blob:
                return &Item{T: byte(ItemBlob), V: v}
        case time.Time:
-               t := tai64n.LeapsecsAdd(v)
+               t := tai64n.Leapsecs.Add(v)
                var taiRaw []byte
                if t.Nanosecond() > 0 {
                        var tai tai64n.TAI64N