Skip to content

time: add time/tzdata package and timetzdata tag to embed tzdata in program #38017

@ianlancetaylor

Description

@ianlancetaylor

Go programs currently rely on the system to provide timezone information in the tzdata database, or rely on GOROOT being accessible at run time in order to read $GOROOT/lib/timezoneinfo.zip. This is not always true, particularly on Windows (#21881) but also in some other environments (#38013).

Therefore, it is desirable for Go program to have some mechanism to directly embed tzdata information into the program itself, so that they don't have to rely on system timezone information that may be absent.

I make the following assumptions, which I think are reasonable:

  • adding the timezone information into a program should be optional, as it increases the size of the program by approximately 800K, and most programs do not need timezone information other than for the local system
  • it should be possible to embed timezone information when building an arbitrary program
  • it should be possible for a program to always embed timezone information without requiring any special build step
  • the program should always prefer data from the system if available, as it is likely to be more up to date than that included in the program

Given those assumptions, I propose adding a new package timezone/tzdata. Importing this package (as import _ "time/tzdata") will cause timezone information to be embedded in the program. Also, building with the build tag timetzdata will force the package to be imported, and therefore will cause timezone information to be embedded in the program. The embedded timezone information will be used if and when no system information is available for the timezone.

There is a sample implementation of this approach at https://golang.org/cl/224588.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions