mirror of https://github.com/0xERR0R/blocky.git
added setLocaltime
This commit is contained in:
parent
f15c7d3190
commit
cf4e894b31
|
@ -4,7 +4,6 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"os"
|
"os"
|
||||||
"time"
|
"time"
|
||||||
_ "time/tzdata"
|
_ "time/tzdata"
|
||||||
|
@ -16,12 +15,27 @@ import (
|
||||||
func init() {
|
func init() {
|
||||||
go reaper.Reap()
|
go reaper.Reap()
|
||||||
|
|
||||||
if tz := os.Getenv("TZ"); tz != "" {
|
setLocaltime()
|
||||||
var err error
|
}
|
||||||
time.Local, err = time.LoadLocation(tz)
|
|
||||||
|
|
||||||
if err != nil {
|
// set localtime to /etc/localtime if available
|
||||||
fmt.Printf("error loading location '%s': %v\n", tz, err)
|
// or modify the system time with the TZ environment variable if it is provided
|
||||||
|
func setLocaltime() {
|
||||||
|
// load /etc/localtime without modifying it
|
||||||
|
if lt, err := os.ReadFile("/etc/localtime"); err == nil {
|
||||||
|
if t, err := time.LoadLocationFromTZData("", lt); err == nil {
|
||||||
|
time.Local = t
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// use zoneinfo from time/tzdata and set location with the TZ environment variable
|
||||||
|
if tz := os.Getenv("TZ"); tz != "" {
|
||||||
|
if t, err := time.LoadLocation(tz); err == nil {
|
||||||
|
time.Local = t
|
||||||
|
|
||||||
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue