MCPcopy Index your code
hub / github.com/coder/coder / TimezoneIANA

Function TimezoneIANA

coderd/util/tz/tz_linux.go:25–45  ·  view source on GitHub ↗

TimezoneIANA attempts to determine the local timezone in IANA format. If the TZ environment variable is set, this is used. Otherwise, /etc/localtime is used to determine the timezone. Reference: https://stackoverflow.com/a/63805394 On Windows platforms, instead of reading /etc/localtime, powershell

()

Source from the content-addressed store, hash-verified

23// is used instead to get the current time location in IANA format.
24// Reference: https://superuser.com/a/1584968
25func TimezoneIANA() (*time.Location, error) {
26 loc, err := locationFromEnv()
27 if err == nil {
28 return loc, nil
29 }
30 if !xerrors.Is(err, errNoEnvSet) {
31 return nil, xerrors.Errorf("lookup timezone from env: %w", err)
32 }
33
34 lp, err := filepath.EvalSymlinks(etcLocaltime)
35 if err != nil {
36 return nil, xerrors.Errorf("read location of %s: %w", etcLocaltime, err)
37 }
38 stripped := strings.ReplaceAll(lp, zoneInfoPath, "")
39 stripped = strings.TrimPrefix(stripped, string(filepath.Separator))
40 loc, err = time.LoadLocation(stripped)
41 if err != nil {
42 return nil, xerrors.Errorf("invalid location %q guessed from %s: %w", stripped, lp, err)
43 }
44 return loc, nil
45}

Callers

nothing calls this directly

Calls 3

locationFromEnvFunction · 0.85
IsMethod · 0.45
ErrorfMethod · 0.45

Tested by

no test coverage detected