Skip to content

Commit

Permalink
Merge pull request #12 from FObersteiner/main
Browse files Browse the repository at this point in the history
use filepath.EvalSymlinks to resolve local tz on Unix
  • Loading branch information
timohuovinen authored Dec 9, 2024
2 parents 2f0e6c7 + 221628f commit 0760d84
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
4 changes: 1 addition & 3 deletions tzlocal/tz.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tzlocal/tz_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
10 changes: 10 additions & 0 deletions tzlocal/tz_unix_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}

0 comments on commit 0760d84

Please sign in to comment.