Files
Reims-Go/internal/host/timezone_other.go
T

25 lines
476 B
Go

//go:build !windows
package host
import (
"os"
"strings"
"time"
)
func DetectHostTimezone() string {
if tz := os.Getenv("TZ"); tz != "Local" && ValidateIANATimezone(tz) {
return tz
}
if link, err := os.Readlink("/etc/localtime"); err == nil {
if _, tz, ok := strings.Cut("/"+link, "/zoneinfo/"); ok && ValidateIANATimezone(tz) {
return tz
}
}
if tz := time.Now().Location().String(); tz != "Local" && ValidateIANATimezone(tz) {
return tz
}
return ""
}