MCPcopy Create free account
hub / github.com/cronitorio/cronitor-cli / effectiveTimezoneLocationName

Function effectiveTimezoneLocationName

cmd/root.go:274–319  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

272}
273
274func effectiveTimezoneLocationName() lib.TimezoneLocationName {
275
276 if runtime.GOOS == "windows" {
277 out, err := exec.Command("powershell", "-NoProfile", "-c", "(Get-TimeZone | Select-Object -First 1 -Property Id).Id | Write-Output").CombinedOutput()
278 if err == nil {
279 return lib.TimezoneLocationName{strings.TrimSpace(fmt.Sprintf("%s", out))}
280 }
281 }
282
283 // First, check if a TZ or CRON_TZ environemnt variable is set -- Diff var used by diff distros
284 if locale, isSetFlag := os.LookupEnv("TZ"); isSetFlag {
285 return lib.TimezoneLocationName{locale}
286 }
287
288 if locale, isSetFlag := os.LookupEnv("CRON_TZ"); isSetFlag {
289 return lib.TimezoneLocationName{locale}
290 }
291
292 // Attempt to parse timedatectl (should work on FreeBSD, many linux distros)
293 if output, err := exec.Command("timedatectl").Output(); err == nil {
294 outputString := strings.Replace(string(output), "Time zone", "Timezone", -1)
295 r := regexp.MustCompile(`(?m:Timezone:\s+(\S+).+$)`)
296 if ret := r.FindStringSubmatch(outputString); ret != nil && len(ret) > 1 {
297 return lib.TimezoneLocationName{ret[1]}
298 }
299 }
300
301 // If /etc/localtime is a symlink, check what it is linking to
302 if localtimeFile, err := os.Lstat("/etc/localtime"); err == nil && localtimeFile.Mode()&os.ModeSymlink == os.ModeSymlink {
303 if symlink, _ := os.Readlink("/etc/localtime"); len(symlink) > 0 {
304 if strings.Contains(symlink, "UTC") {
305 return lib.TimezoneLocationName{"UTC"}
306 }
307
308 symlinkParts := strings.Split(symlink, "/")
309 return lib.TimezoneLocationName{strings.Join(symlinkParts[len(symlinkParts)-2:], "/")}
310 }
311 }
312
313 // If we happen to have an /etc/timezone, no guarantee it's used, but read that
314 if locale, err := ioutil.ReadFile("/etc/timezone"); err == nil {
315 return lib.TimezoneLocationName{string(locale)}
316 }
317
318 return lib.TimezoneLocationName{""}
319}
320
321func defaultConfigFileDirectory() string {
322 if runtime.GOOS == "windows" {

Callers 5

configure.goFile · 0.85
processCrontabFunction · 0.85
handleSettingsFunction · 0.85
handleGetJobsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected