MCPcopy Create free account
hub / github.com/1Panel-dev/1Panel / LoadTimeZoneByCmd

Function LoadTimeZoneByCmd

core/utils/common/time.go:11–31  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

9)
10
11func LoadTimeZoneByCmd() string {
12 loc := time.Now().Location().String()
13 if _, err := time.LoadLocation(loc); err != nil {
14 loc = "Asia/Shanghai"
15 }
16 std, err := cmd.NewCommandMgr().RunWithStdout("timedatectl")
17 if err != nil {
18 return loc
19 }
20 for _, line := range strings.Split(std, "\n") {
21 fields := strings.Fields(line)
22 if len(fields) != 5 || fields[0] != "Time" || fields[1] != "zone:" {
23 continue
24 }
25 if _, err := time.LoadLocation(fields[2]); err != nil {
26 return loc
27 }
28 return fields[2]
29 }
30 return loc
31}
32
33func LoadExpiredLocation() *time.Location {
34 var (

Callers 1

LoadExpiredLocationFunction · 0.70

Calls 2

StringMethod · 0.45
RunWithStdoutMethod · 0.45

Tested by

no test coverage detected