adding the go utilities
This commit is contained in:
parent
7ab9bd207d
commit
a5711052c7
16
go/convert-epoch/README.md
Normal file
16
go/convert-epoch/README.md
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
# Build the binary
|
||||||
|
|
||||||
|
This will likely change into some sort of `Makefile` later, but for now what is needed to build and use this utility is to run the followning commands:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ export GOPATH=/home/mock/.local/bin
|
||||||
|
$ go build .
|
||||||
|
$ convert-epoch -epoch 1631711695
|
||||||
|
Epoch time: 1631711695
|
||||||
|
Local time: Wed, 15 Sep 2021 09:14:55 -0400
|
||||||
|
Zulu time: Wed, 15 Sep 2021 13:14:55 +0000
|
||||||
|
```
|
||||||
|
|
||||||
|
I would like to remove the `-epoch` flag in favor of just assuming an epoch time value, but that will come later too. Gotta keep learning the language.
|
||||||
|
|
||||||
|
|
47
go/convert-epoch/convert-epoch.go
Normal file
47
go/convert-epoch/convert-epoch.go
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"flag"
|
||||||
|
"fmt"
|
||||||
|
"strconv"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
// Color for extra touch
|
||||||
|
type Color string
|
||||||
|
|
||||||
|
const (
|
||||||
|
Black Color = "\u001b[30m"
|
||||||
|
Red = "\u001b[31m"
|
||||||
|
BoldRed = "\u001b[91m"
|
||||||
|
Green = "\u001b[32m"
|
||||||
|
BoldGreen = "\u001b[92m"
|
||||||
|
Yellow = "\u001b[33m"
|
||||||
|
BoldYellow = "\u001b[93m"
|
||||||
|
Blue = "\u001b[34m"
|
||||||
|
BoldBlue = "\u001b[94m"
|
||||||
|
Reset = "\u001b[0m"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Simplify the color printing
|
||||||
|
func cprint(color Color, title string, time_value string) {
|
||||||
|
fmt.Println(string(Yellow), title, string(color), time_value, string(Reset))
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
epoch_now := time.Now().Unix()
|
||||||
|
// cprint(Red, "Now time: ", time.Unix(epoch_now, 0).Format(time.RFC1123Z))
|
||||||
|
|
||||||
|
epoch_time := flag.Int64("epoch", epoch_now, "Supply epoch time value")
|
||||||
|
flag.Parse()
|
||||||
|
cprint(Red, "Epoch time: ", strconv.FormatInt(*epoch_time, 10))
|
||||||
|
|
||||||
|
local_time := time.Unix(*epoch_time, 0).Format(time.RFC1123Z)
|
||||||
|
cprint(BoldBlue, "Local time: ", local_time)
|
||||||
|
|
||||||
|
zulu_time := time.Unix(*epoch_time, 0).UTC().Format(time.RFC1123Z)
|
||||||
|
cprint(BoldGreen, "Zulu time: ", zulu_time)
|
||||||
|
}
|
||||||
|
|
3
go/convert-epoch/go.mod
Normal file
3
go/convert-epoch/go.mod
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
module convert-epoch
|
||||||
|
|
||||||
|
go 1.16
|
Loading…
Reference in New Issue
Block a user