X-Git-Url: http://www.git.cypherpunks.ru/?a=blobdiff_plain;f=cmd%2Ftai64nlocal%2Fmain.go;h=04bce9dfd5b8fafd10aff0e0ae246cea2c462a0d;hb=1212e4f1f980bead7213aaf8fe029395d2ecae13;hp=4b58127a6fdfabd0a74da6ee3c64a835b8bbb340;hpb=266a0ae363ebb2c96e0a1d700c20bfc3a3188788;p=gotai64n.git diff --git a/cmd/tai64nlocal/main.go b/cmd/tai64nlocal/main.go index 4b58127..04bce9d 100644 --- a/cmd/tai64nlocal/main.go +++ b/cmd/tai64nlocal/main.go @@ -1,6 +1,6 @@ /* -go.cypherpunks.ru/tai64n -- Pure Go TAI64N implementation -Copyright (C) 2020-2021 Sergey Matveev +go.cypherpunks.ru/tai64n -- Pure Go TAI64/TAI64N implementation +Copyright (C) 2020-2022 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 @@ -19,16 +19,38 @@ package main import ( "bufio" + "flag" + "fmt" + "io/ioutil" "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 := ioutil.ReadFile(*db) + if err != nil { + log.Fatalln(err) + } + tai64n.LeapsecsDBLoad(buf) + } + scanner := bufio.NewScanner(os.Stdin) var err error var s string @@ -55,6 +77,9 @@ func main() { if err != nil { log.Fatalln(err) } + if *leapsecs { + t = tai64n.LeapsecsSub(t) + } os.Stdout.WriteString(t.Format(tai64n.LocalFmt) + s[sep:] + "\n") } }