]> Cypherpunks.ru repositories - gotai64n.git/blob - cmd/leapsecsdb/main.go
Raised copyright years
[gotai64n.git] / cmd / leapsecsdb / main.go
1 /*
2 go.cypherpunks.ru/tai64n -- Pure Go TAI64/TAI64N implementation
3 Copyright (C) 2020-2022 Sergey Matveev <stargrave@stargrave.org>
4
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, version 3 of the License.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 */
17
18 package main
19
20 import (
21         "bufio"
22         "flag"
23         "fmt"
24         "log"
25         "os"
26         "time"
27
28         "go.cypherpunks.ru/tai64n/v2"
29 )
30
31 func main() {
32         log.SetFlags(0)
33         flag.Usage = func() {
34                 fmt.Fprintf(
35                         flag.CommandLine.Output(),
36                         `Convert YYYY-MM-DD dates to TAI64 timestamps.
37 $ leapsecsdb > leapsecs.dat <<EOF
38 1972-07-01
39 1973-01-01
40 EOF
41 `,
42                 )
43                 flag.PrintDefaults()
44         }
45         flag.Parse()
46
47         scanner := bufio.NewScanner(os.Stdin)
48         var err error
49         var t time.Time
50         tai := new(tai64n.TAI64)
51         for {
52                 if !scanner.Scan() {
53                         if err = scanner.Err(); err != nil {
54                                 log.Fatalln(err)
55                         }
56                         break
57                 }
58                 t, err = time.Parse("2006-01-02", scanner.Text())
59                 if err != nil {
60                         log.Fatalln(err)
61                 }
62                 tai.FromTime(t)
63                 if _, err = os.Stdout.Write(tai[:]); err != nil {
64                         log.Fatalln(err)
65                 }
66         }
67 }