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
()
| 23 | // is used instead to get the current time location in IANA format. |
| 24 | // Reference: https://superuser.com/a/1584968 |
| 25 | func 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 | } |
nothing calls this directly
no test coverage detected