+/*
+goredo -- redo implementation on pure Go
+Copyright (C) 2020 Sergey Matveev <stargrave@stargrave.org>
+
+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 <http://www.gnu.org/licenses/>.
+*/
+
package main
import (
- "encoding/binary"
+ "bufio"
+ "io"
+ "strings"
"time"
+
+ "go.cypherpunks.ru/tai64n"
)
-type TAI64N [12]byte
+func tai64nLocal(dst io.StringWriter, src io.Reader) error {
+ scanner := bufio.NewScanner(src)
+ var err error
+ var s string
+ var sep int
+ var t time.Time
+ for {
+ if !scanner.Scan() {
+ if err = scanner.Err(); err != nil {
+ return err
+ }
+ break
+ }
+ s = scanner.Text()
-func tai64nNow(ts *TAI64N) {
- t := time.Now()
- binary.BigEndian.PutUint64(ts[:], uint64(0x400000000000000a)+uint64(t.Unix()))
- binary.BigEndian.PutUint32(ts[8:], uint32(t.Nanosecond()))
+ if s[0] != '@' {
+ dst.WriteString(s + "\n")
+ }
+ sep = strings.IndexByte(s, byte(' '))
+ if sep == -1 {
+ dst.WriteString(s + "\n")
+ }
+ t, err = tai64n.Decode(s[1:sep])
+ if err != nil {
+ return err
+ }
+ dst.WriteString(t.Format(tai64n.LocalFmt) + s[sep:] + "\n")
+ }
+ return nil
}