this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

unixtime: add a new thing

+102 -1
+2 -1
go.mod
··· 19 19 20 20 require ( 21 21 github.com/ChannelMeter/iso8601duration v0.0.0-20150204201828-8da3af7a2a61 // indirect 22 + github.com/araddon/dateparse v0.0.0-20210429162001-6b43995a97de // indirect 22 23 github.com/gorilla/websocket v1.4.2 // indirect 23 - github.com/stretchr/testify v1.6.1 // indirect 24 + github.com/stretchr/testify v1.7.0 // indirect 24 25 gopkg.in/yaml.v3 v3.0.0-20200605160147-a5ece683394c // indirect 25 26 )
+6
go.sum
··· 3 3 github.com/ChannelMeter/iso8601duration v0.0.0-20150204201828-8da3af7a2a61/go.mod h1:GnKXcK+7DYNy/8w2Ex//Uql4IgfaU82Cd5rWKb7ah00= 4 4 github.com/apognu/gocal v0.9.0 h1:2lGdZprjYs9A6l1RTEmapmpE1PiDbXNX8bUVqZt3vm4= 5 5 github.com/apognu/gocal v0.9.0/go.mod h1:ZOJfNOqpz8aasi3uqzDu+eWTT6VuEa/TvQWiYYWlb80= 6 + github.com/araddon/dateparse v0.0.0-20210429162001-6b43995a97de h1:FxWPpzIjnTlhPwqqXc4/vE0f7GvRjuAsbW+HOIe8KnA= 7 + github.com/araddon/dateparse v0.0.0-20210429162001-6b43995a97de/go.mod h1:DCaWoUhZrYW9p1lxo/cm8EmUOOzAPSEZNGF2DK1dJgw= 6 8 github.com/channelmeter/iso8601duration v0.0.0-20150204201828-8da3af7a2a61 h1:o64h9XF42kVEUuhuer2ehqrlX8rZmvQSU0+Vpj1rF6Q= 7 9 github.com/channelmeter/iso8601duration v0.0.0-20150204201828-8da3af7a2a61/go.mod h1:Rp8e0DCtEKwXFOC6JPJQVTz8tuGoGvw6Xfexggh/ed0= 8 10 github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= ··· 26 28 github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= 27 29 github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y= 28 30 github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94= 31 + github.com/mattn/go-runewidth v0.0.10/go.mod h1:RAqKPSqVFrSLVXbA8x7dzmKdmGzieGRCM46jaSJTDAk= 29 32 github.com/nlopes/slack v0.6.0 h1:jt0jxVQGhssx1Ib7naAOZEZcGdtIhTzkP0nopK0AsRA= 30 33 github.com/nlopes/slack v0.6.0/go.mod h1:JzQ9m3PMAqcpeCam7UaHSuBuupz7CmpjehYMayT6YOk= 31 34 github.com/pelletier/go-toml v1.6.0/go.mod h1:5N711Q9dKgbdkxHL+MEfF31hpT7l0S0s/t2kKREewys= ··· 37 40 github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= 38 41 github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= 39 42 github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= 43 + github.com/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= 44 + github.com/scylladb/termtables v0.0.0-20191203121021-c4c0b6d42ff4/go.mod h1:C1a7PQSMz9NShzorzCiG2fk9+xuCgLkPeCvMHYR2OWg= 40 45 github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= 41 46 github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= 42 47 github.com/stretchr/testify v1.2.0/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= 43 48 github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= 44 49 github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0= 45 50 github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= 51 + github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= 46 52 golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= 47 53 golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= 48 54 golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
+94
unixtime/main.go
··· 1 + package main 2 + 3 + import ( 4 + "bufio" 5 + "context" 6 + "flag" 7 + "fmt" 8 + "io" 9 + "os" 10 + "time" 11 + 12 + "github.com/araddon/dateparse" 13 + "github.com/peterbourgon/ff/v3/ffcli" 14 + ) 15 + 16 + func main() { 17 + if err := realMain( 18 + context.Background(), 19 + os.Stdin, 20 + os.Stdout, 21 + os.Stderr, 22 + os.Args, 23 + ); err != nil { 24 + fmt.Fprintf(os.Stderr, "%s\n", err) 25 + os.Exit(1) 26 + } 27 + } 28 + 29 + func realMain( 30 + ctx context.Context, 31 + stdin io.Reader, 32 + stdout io.Writer, 33 + stderr io.Writer, 34 + args []string, 35 + ) error { 36 + exec := args[0] 37 + 38 + nowCmd := &ffcli.Command{ 39 + Name: "now", 40 + ShortHelp: "Current time in epoch seconds", 41 + Exec: func(_ context.Context, _ []string) error { 42 + fmt.Fprintln(stdout, time.Now().Unix()) 43 + return nil 44 + }, 45 + } 46 + 47 + decodeCmd := &ffcli.Command{ 48 + Name: "decode", 49 + ShortHelp: "Decode given epoch seconds input to human readable time", 50 + Exec: func(_ context.Context, _ []string) error { 51 + s := bufio.NewScanner(stdin) 52 + for s.Scan() { 53 + t, err := dateparse.ParseAny(s.Text()) 54 + if err != nil { 55 + fmt.Fprintf(stderr, "ERROR: %v\n", err) 56 + continue 57 + } 58 + 59 + fmt.Fprintln(stdout, t.UTC().Format(time.RFC3339)) 60 + } 61 + 62 + return nil 63 + }, 64 + } 65 + 66 + encodeCmd := &ffcli.Command{ 67 + Name: "encode", 68 + ShortHelp: "Encode given human readable time to epoch seconds", 69 + Exec: func(_ context.Context, _ []string) error { 70 + s := bufio.NewScanner(stdin) 71 + for s.Scan() { 72 + t, err := dateparse.ParseAny(s.Text()) 73 + if err != nil { 74 + fmt.Fprintf(stderr, "ERROR: %v\n", err) 75 + continue 76 + } 77 + 78 + fmt.Fprintln(stdout, t.UTC().Unix()) 79 + } 80 + 81 + return nil 82 + }, 83 + } 84 + 85 + rootCmd := &ffcli.Command{ 86 + ShortUsage: fmt.Sprintf("%v <subcommand>", exec), 87 + Subcommands: []*ffcli.Command{nowCmd, decodeCmd, encodeCmd}, 88 + Exec: func(_ context.Context, args []string) error { 89 + return flag.ErrHelp 90 + }, 91 + } 92 + 93 + return rootCmd.ParseAndRun(ctx, args[1:]) 94 + }