GetLocalTimezone tries to find local timezone from $TZ or /etc/localtime symlink
()
| 479 | |
| 480 | // GetLocalTimezone tries to find local timezone from $TZ or /etc/localtime symlink |
| 481 | func GetLocalTimezone() (string, error) { |
| 482 | timezone := "" |
| 483 | if os.Getenv("TZ") != "" { |
| 484 | timezone = os.Getenv("TZ") |
| 485 | } else { |
| 486 | localtimeFile := filepath.Join("/etc", "localtime") |
| 487 | var err error |
| 488 | timezone, err = filepath.EvalSymlinks(localtimeFile) |
| 489 | if err != nil { |
| 490 | return "", fmt.Errorf("unable to read timezone from %s file: %v", localtimeFile, err) |
| 491 | } |
| 492 | } |
| 493 | return GetTimezone(timezone) |
| 494 | } |
| 495 | |
| 496 | // SubtractSlices removes elements of slice b from slice a. |
| 497 | func SubtractSlices(a, b []string) []string { |