Add TZ env usage to set local time zone.

This commit is contained in:
davidnewhall2
2020-06-13 18:46:02 -07:00
parent b46b31827e
commit b7c83eebbb
5 changed files with 135 additions and 13 deletions

17
main.go
View File

@@ -2,6 +2,8 @@ package main
import (
"log"
"os"
"time"
"github.com/unifi-poller/poller"
@@ -16,7 +18,22 @@ import (
// Keep it simple.
func main() {
// Set time zone based on TZ env variable.
setTimeZone(os.Getenv("TZ"))
if err := poller.New().Start(); err != nil {
log.Fatalln("[ERROR]", err)
}
}
func setTimeZone(tz string) {
if tz == "" {
return
}
var err error
if time.Local, err = time.LoadLocation(tz); err != nil {
log.Printf("[ERROR] Loading TZ Location '%s': %v\n", tz, err)
}
}