X-Git-Url: http://www.git.cypherpunks.ru/?a=blobdiff_plain;f=cmd%2Ftai64nlocal%2Fmain.go;h=4fa1926bc1c700c7edb6f8cd0f6e4ff5ba4f86df;hb=HEAD;hp=571c30ac8ffe87271312af27bbc130b685ea085e;hpb=409705fa3bbf9f18c6df91be80199d4d14c234d2;p=gotai64n.git diff --git a/cmd/tai64nlocal/main.go b/cmd/tai64nlocal/main.go index 571c30a..4fa1926 100644 --- a/cmd/tai64nlocal/main.go +++ b/cmd/tai64nlocal/main.go @@ -1,34 +1,53 @@ -/* -go.cypherpunks.ru/tai64n -- Pure Go TAI64N implementation -Copyright (C) 2020-2021 Sergey Matveev - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, version 3 of the License. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see . -*/ +// go.cypherpunks.ru/tai64n -- Pure Go TAI64/TAI64N implementation +// Copyright (C) 2020-2024 Sergey Matveev +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, version 3 of the License. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . package main import ( "bufio" + "flag" + "fmt" "log" "os" "strings" "time" - "go.cypherpunks.ru/tai64n" + "go.cypherpunks.ru/tai64n/v2" ) func main() { log.SetFlags(0) + flag.Usage = func() { + fmt.Fprintf( + flag.CommandLine.Output(), + "Replace \"@HEX(TAI64)\"-prefixed line with human readable UTC.\n", + ) + flag.PrintDefaults() + } + leapsecs := flag.Bool("leapsecs", false, "Take leap seconds into account: honest TAI->UTC") + db := flag.String("leapsecsdb", "", "Use that leapsecs.dat leap seconds database") + flag.Parse() + + if *db != "" { + buf, err := os.ReadFile(*db) + if err != nil { + log.Fatalln(err) + } + tai64n.LeapsecsDBLoad(buf) + } + scanner := bufio.NewScanner(os.Stdin) var err error var s string @@ -44,15 +63,20 @@ func main() { s = scanner.Text() if s[0] != '@' { os.Stdout.WriteString(s + "\n") + continue } sep = strings.IndexByte(s, byte(' ')) if sep == -1 { os.Stdout.WriteString(s + "\n") + continue } t, err = tai64n.Decode(s[1:sep]) if err != nil { log.Fatalln(err) } + if *leapsecs { + t = tai64n.LeapsecsSub(t) + } os.Stdout.WriteString(t.Format(tai64n.LocalFmt) + s[sep:] + "\n") } }