mirror of
https://github.com/coder/coder.git
synced 2025-07-03 16:13:58 +00:00
This commit adds the following changes: - autostart enable|disable => autostart set|unset - autostart enable now accepts a more natual schedule format: <time> <days-of-week> <location> - autostart show now shows configured timezone - 🎉 automatic timezone detection across mac, windows, linux 🎉 Fixes #1647
31 lines
539 B
Go
31 lines
539 B
Go
// Package tz includes utilities for cross-platform timezone/location detection.
|
|
package tz
|
|
|
|
import (
|
|
"os"
|
|
"time"
|
|
|
|
"golang.org/x/xerrors"
|
|
)
|
|
|
|
var errNoEnvSet = xerrors.New("no env set")
|
|
|
|
func locationFromEnv() (*time.Location, error) {
|
|
tzEnv, found := os.LookupEnv("TZ")
|
|
if !found {
|
|
return nil, errNoEnvSet
|
|
}
|
|
|
|
// TZ set but empty means UTC.
|
|
if tzEnv == "" {
|
|
return time.UTC, nil
|
|
}
|
|
|
|
loc, err := time.LoadLocation(tzEnv)
|
|
if err != nil {
|
|
return nil, xerrors.Errorf("load location from TZ env: %w", err)
|
|
}
|
|
|
|
return loc, nil
|
|
}
|