-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
command/flag: add timezone flag to common task flags
- Add Timezone type - Resolve timezone name from /etc/localtime
- Loading branch information
Showing
5 changed files
with
81 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// Copyright (C) 2021 ScyllaDB | ||
|
||
package timeutc | ||
|
||
import ( | ||
"os" | ||
"strings" | ||
"time" | ||
) | ||
|
||
// LocalName is name of the local time zone conforming to the IANA Time Zone database, such as "America/New_York". | ||
// Using time.Local if timezone is read from /etc/localtime its name is overwritten by "Local". | ||
// LocalName provides the name as read from /etc/localtime static link. | ||
var LocalName string | ||
|
||
func init() { | ||
tz := time.Local.String() | ||
if tz == "Local" { | ||
p, err := os.Readlink("/etc/localtime") | ||
if err != nil { | ||
return | ||
} | ||
i := strings.LastIndex(p, "/zoneinfo/") | ||
if i < 0 { | ||
return | ||
} | ||
tz = p[i+len("/zoneinfo/"):] | ||
if _, err := time.LoadLocation(tz); err != nil { | ||
return | ||
} | ||
} | ||
|
||
LocalName = tz | ||
} |