]> Cypherpunks repositories - keks.git/commitdiff
Omit empty ns/as
authorSergey Matveev <stargrave@stargrave.org>
Tue, 15 Apr 2025 08:13:59 +0000 (11:13 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Tue, 15 Apr 2025 08:13:59 +0000 (11:13 +0300)
go/cmd/pp/tcl.go

index aeb0daacf173339f27532c7da709519094bd5dd4ce280d0de381b35e4fa52e27..fc08e325df4c3205ae1c58dab877a9c8fe442a507dedbcf5b6ada87dee845ced 100644 (file)
@@ -29,7 +29,7 @@ import (
        "go.cypherpunks.su/tai64n/v4"
 )
 
-func tclTAI(t time.Time, ns int, as uint64) {
+func tclTAI(t time.Time, ns, as int) {
        utc, isLeap := tai64n.Leapsecs.Sub(t)
        year := utc.Year()
        if year < 0 {
@@ -38,8 +38,14 @@ func tclTAI(t time.Time, ns int, as uint64) {
        if isLeap || year > 9999 {
                fmt.Printf("TAI64 %d %d %d", t.Unix(), ns, as)
        } else {
-               fmt.Printf("TAI64 [ToTAI [ISOToSec \"%s\"]] %d %d",
-                       utc.Format("2006-01-02 15:04:05"), ns, as)
+               s := `TAI64 [ToTAI [ISOToSec "` + utc.Format("2006-01-02 15:04:05") + `"]]`
+               if ns > 0 {
+                       s += " " + strconv.Itoa(ns)
+               }
+               if as > 0 {
+                       s += " " + strconv.Itoa(as)
+               }
+               fmt.Print(s)
        }
 }
 
@@ -116,7 +122,7 @@ func tcl(iter *keks.Iterator, count int, inList, inMap bool) {
                                var n tai64n.TAI64N
                                copy(n[:], tai[:])
                                t := n.Time()
-                               tclTAI(t, t.Nanosecond(), be.Get(tai[12:]))
+                               tclTAI(t, t.Nanosecond(), int(be.Get(tai[12:])))
                        case types.Magic:
                                allPrintable := true
                                magic := iter.Magic()