diff --git a/tzlocal/tz.go b/tzlocal/tz.go index 473ae51..d2e3d64 100644 --- a/tzlocal/tz.go +++ b/tzlocal/tz.go @@ -25,7 +25,6 @@ func EnvTZ() (string, bool) { // RuntimeTZ get the full timezone name of the local machine func RuntimeTZ() (string, error) { - // Get the timezone from the TZ env variable if name, ok := EnvTZ(); ok { return name, nil @@ -34,8 +33,7 @@ func RuntimeTZ() (string, error) { // Get the timezone from the system file name, err := LocalTZ() if err != nil { - err = fmt.Errorf("failed to get local machine timezone: %w", err) - return "", err + return "", fmt.Errorf("failed to get local machine timezone: %w", err) } return name, err diff --git a/tzlocal/tz_unix.go b/tzlocal/tz_unix.go index bd4ad3c..02f8684 100644 --- a/tzlocal/tz_unix.go +++ b/tzlocal/tz_unix.go @@ -46,7 +46,7 @@ func LocalTZ() (string, error) { return name, err } - p, err := os.Readlink(localZoneFile) + p, err := filepath.EvalSymlinks(localZoneFile) if err != nil { return name, err } diff --git a/tzlocal/tz_unix_test.go b/tzlocal/tz_unix_test.go index 5f3c856..68e87d3 100644 --- a/tzlocal/tz_unix_test.go +++ b/tzlocal/tz_unix_test.go @@ -57,3 +57,13 @@ func Test_inferFromPath(t *testing.T) { }) } } + +func TestRuntimeTZ(t *testing.T) { + got, err := RuntimeTZ() + if err != nil { + t.Errorf("RuntimeTZ failed with %v", err.Error()) + } + if got == "" { + t.Error("RuntimeTZ returned empty timezone string") + } +}