X-Git-Url: http://www.git.cypherpunks.ru/?p=gotai64n.git;a=blobdiff_plain;f=cmd%2Ftai64nlocal%2Fmain.go;fp=cmd%2Ftai64nlocal%2Fmain.go;h=2f3ed153f17f436b3ec5d6ac98245ea071ee0bc6;hp=0000000000000000000000000000000000000000;hb=dd683a282f1b02438967936e85a8601f90f29400;hpb=bb4c17edb1b1f764c1dd297d98f677372ff772ec diff --git a/cmd/tai64nlocal/main.go b/cmd/tai64nlocal/main.go new file mode 100644 index 0000000..2f3ed15 --- /dev/null +++ b/cmd/tai64nlocal/main.go @@ -0,0 +1,58 @@ +/* +go.cypherpunks.ru/tai64n -- Pure Go TAI64N implementation +Copyright (C) 2020 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" + "log" + "os" + "strings" + "time" + + "go.cypherpunks.ru/tai64n" +) + +func main() { + log.SetFlags(0) + scanner := bufio.NewScanner(os.Stdin) + var err error + var s string + var sep int + var t time.Time + for { + if !scanner.Scan() { + if err = scanner.Err(); err != nil { + log.Fatalln(err) + } + break + } + s = scanner.Text() + if s[0] != '@' { + os.Stdout.WriteString(s + "\n") + } + sep = strings.IndexByte(s, byte(' ')) + if sep == -1 { + os.Stdout.WriteString(s + "\n") + } + t, err = tai64n.Decode(s[1:sep]) + if err != nil { + log.Fatalln(err) + } + os.Stdout.WriteString(t.Format(tai64n.LocalFmt) + s[sep:] + "\n") + } +}