After reading Jon Skeet's excellent blog post about issues with storing datetimes in UTC inside applications I wondered, how Go was dealing with updates to timezones. In Python this is done using the pytz package which is updated frequently. Go goes a slightly different way:
On Unix systems it tries to load information about the current timezone from one of the following places (src/time/zoneinfo_unix.go:21):
var zoneSources = []string{
"/usr/share/zoneinfo/",
"/usr/share/lib/zoneinfo/",
"/usr/lib/locale/TZ/",
runtime.GOROOT() + "/lib/time/zoneinfo.zip",
}
/usr/share/zoneinfo
is a folder that is usually provided by the tzdata package of whatever Linux distribution you're using. This in turn is built based on data provided by the tz database project which is maintained by the IANA. You can get the "original" data and project code on https://www.iana.org/time-zones. If you want to get notified when something changes there, there is even an annoucement mailing list!
If you want to stay up-to-date here (and you definitely want!) then it's probably easiest to just stick with the package provided by your operating system. Looking at, for instance, Debian's tzdata package for Jessie, it still gets updated and is currently at 2019c which is the latest release of the tz database at the time of writing this.
At the other end of the spectrum you can also force Go to explicitly use a path of your choosing by setting the ZONEINFO
environment variable. You could even roll your own zoneinfo.zip
file: The lib/time folder inside Go's source tree contains an update.bash
file which should come in handy there.
To summarize: If you want to stay up-to-date with your timezone information in Go applications, Go makes that pretty simple by sticking close to what the operating system provides. For edge cases you are able to roll your own version of the tz database, though.
Top comments (0)