diff --git a/go/convert-epoch/README.md b/go/convert-epoch/README.md new file mode 100644 index 0000000..2a5e859 --- /dev/null +++ b/go/convert-epoch/README.md @@ -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. + + diff --git a/go/convert-epoch/convert-epoch.go b/go/convert-epoch/convert-epoch.go new file mode 100644 index 0000000..7620fd5 --- /dev/null +++ b/go/convert-epoch/convert-epoch.go @@ -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) +} + diff --git a/go/convert-epoch/go.mod b/go/convert-epoch/go.mod new file mode 100644 index 0000000..6906be8 --- /dev/null +++ b/go/convert-epoch/go.mod @@ -0,0 +1,3 @@ +module convert-epoch + +go 1.16