]> Cypherpunks repositories - keks.git/commitdiff
Better TAI-related testing
authorSergey Matveev <stargrave@stargrave.org>
Fri, 22 Nov 2024 15:19:44 +0000 (18:19 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Fri, 22 Nov 2024 15:19:44 +0000 (18:19 +0300)
cyac/lib/enctai.c
gyac/go.mod
gyac/go.sum
pyac/pyac.py

index 9aa807482a631779d036ae3274db167a6ad6a634e9fcfbc2455c48d6f1931362..eab6f7fb76ce2ab3286042dbe795a1c0386befaf7adeaaa5927dc753511ba4d0 100644 (file)
@@ -38,17 +38,12 @@ YACTimespecToTAI64(unsigned char *buf, const struct timespec *ts)
 bool
 YACTimespecToTAI(struct timespec *ts)
 {
-    int64_t v = (int64_t)(ts->tv_sec);
-    int64_t i = 0;
-    for (; i < YACLeapsecsN; i++) {
-        if (v < YACLeapsecs[i]) {
-            break;
+    int64_t v = 10 + (int64_t)(ts->tv_sec);
+    for (int64_t i = 0; i < YACLeapsecsN; i++) {
+        if (v >= YACLeapsecs[i]) {
+            v++;
         }
     }
-    v += (int64_t)10 + i;
-    if (v == YACLeapsecs[i]) {
-        v++;
-    }
     if (((uint64_t)1 << ((sizeof(time_t) * 8) - 1)) < (uint64_t)v) {
         return false;
     }
index e8990e996fa665a9c1bbb3259508d0c15f19f5b709c32b32b9a125446485a8d9..7ec9b5a67b54eeaa9ca6f68a67c7dd92ad8d1a19e7210ee917d78a37635aee23 100644 (file)
@@ -2,7 +2,7 @@ module go.cypherpunks.su/yac/gyac
 
 go 1.22
 
-require go.cypherpunks.su/tai64n/v4 v4.0.0
+require go.cypherpunks.su/tai64n/v4 v4.1.0
 
 require (
        github.com/google/uuid v1.6.0
index 4fea018dcd9c5908f005ae8ce280b45be25e226846c01aefee3f13807d712866..063c682ef8bc10d607af9505018ff485e66d94e8febb95a5a280ac024547ac33 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/v4 v4.0.0 h1:jFEoz3XLOdimA0ZXarzRvGYNublOpgFv04r656UrYiI=
-go.cypherpunks.su/tai64n/v4 v4.0.0/go.mod h1:/uKUdhLOy8UciRKpapPaFXSOoa/SiXjs3XsDDpAz7OA=
+go.cypherpunks.su/tai64n/v4 v4.1.0 h1:jW0EyklKXpSy9DSFMcDbu7XuLlMkn6kkpNWiMG6UT5c=
+go.cypherpunks.su/tai64n/v4 v4.1.0/go.mod h1:/uKUdhLOy8UciRKpapPaFXSOoa/SiXjs3XsDDpAz7OA=
index 5d9a0b2f180f03861554748cc772c106330ba5729f5cf9303ab7bbbdfdeab2ef..d3708ef56c702a7603928696aa106f14e09fa1152aa9bb44cb8426c8c51b9069 100755 (executable)
@@ -154,12 +154,10 @@ def _str(v, utf8):
 def utc2tai(secs):
     """Add leapseconds to UTC
     """
-    for diff, leapsec in enumerate(Leapsecs):
-        if secs < leapsec:
-            break
-    secs += Leapsecs1972 + diff
-    if secs == leapsec:
-        secs += 1
+    secs += Leapsecs1972
+    for leapsec in Leapsecs:
+        if secs >= leapsec:
+            secs += 1
     return secs
 
 
@@ -175,13 +173,15 @@ def dumps(v):
     if isinstance(v, float):
         raise NotImplementedError("no FLOAT* support")
     if isinstance(v, datetime):
+        ms = v.microsecond
+        v = v.replace(microsecond=0)
         secs = int(v.replace(tzinfo=timezone.utc).timestamp())
         secs = utc2tai(secs) + TAI64Base
-        if v.microsecond == 0:
+        if ms == 0:
             return _byte(TagTAI64) + secs.to_bytes(8, "big")
         return (
             _byte(TagTAI64N) + secs.to_bytes(8, "big") +
-            (v.microsecond * 1000).to_bytes(4, "big")
+            (ms * 1000).to_bytes(4, "big")
         )
     if isinstance(v, Raw):
         return _byte(v.t) + v.v