Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

proposal: time: List timezones #20211

Closed
Merovius opened this issue May 2, 2017 · 5 comments

Comments

Projects
None yet
4 participants
@Merovius
Copy link

commented May 2, 2017

I'd like to propose to add a function to the time package that lists the set of installed timezones. For a good user experience, I want my service to provide auto completion or a drop-down for a user to select their timezone; currently, the time package only supports probing, which would make for a bad user-experience.

In theory, this could be provided outside of the stdlib by walking the corresponding directory trees; however, for different systems, different directories are used, so this would require duplicating those lists and keeping them in sync with the stdlib manually (otherwise you might claim to support a timezone, which you then not actually support; again, a bad user experience).

I'd write this myself, but wanted to first get an opinion on whether this would be accepted.

System details

go version go1.8.1 linux/amd64
GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH=""
GORACE=""
GOROOT="/home/axelw/go"
GOTOOLDIR="/home/axelw/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build049658130=/tmp/go-build -gno-record-gcc-switches"
CXX="g++"
CGO_ENABLED="1"
PKG_CONFIG="pkg-config"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
GOROOT/bin/go version: go version go1.8.1 linux/amd64
GOROOT/bin/go tool compile -V: compile version go1.8.1 X:framepointer
uname -sr: Linux 4.4.0-72-generic
Distributor ID:	Ubuntu
Description:	Ubuntu 14.04.5 LTS
Release:	14.04
Codename:	trusty
/lib/x86_64-linux-gnu/libc.so.6: GNU C Library (Ubuntu EGLIBC 2.19-0ubuntu6.11) stable release version 2.19, by Roland McGrath et al.
gdb --version: GNU gdb (GDB) 7.9-gg19

@bradfitz bradfitz changed the title time: List timezones proposal: time: List timezones May 2, 2017

@gopherbot gopherbot added this to the Proposal milestone May 2, 2017

@gopherbot gopherbot added the Proposal label May 2, 2017

@rsc

This comment has been minimized.

Copy link
Contributor

commented May 15, 2017

Someone would have to put readdir etc into package time (which cannot import os), at the bare minimum. Then the implementation would have to read the TZ database directory and open and read every file? Or maybe just list them and let the caller open them?

It's true that package time knows best where it will search from LoadLocation, and returning the directory is not super-helpful on Windows or other systems that have it in the zip file in GOROOT. So you can't write this function outside the standard library.

On the other hand it seems very specialized.

@Merovius

This comment has been minimized.

Copy link
Author

commented May 16, 2017

I did not think about the restrictions about importing packages; that, indeed, complicates things and changes the tradeoffs significantly. TBH, I don't find it that specialized. I'd argue that most software that exposes timezones to users probably wants this, or risk being very frustrating to users. I know I often don't know what to call the timezone I'm about; what major city to use (and daylight savings time makes zone abbreviations pretty useless too, AIUI). But yeah, I can see how it's probably specialized enough to not justify the tradeoffs under these circumstances.

I'd still love to see this (maybe in x/, which doesn't have the restriction on imports but would still have reasonable guarantees to stay in sync with the stdlib?), but understand if you decide to not do it.

@bradfitz

This comment has been minimized.

Copy link
Member

commented Jun 12, 2017

Related issue: #20629 ("time: Add function to generate a Location struct")

@rsc

This comment has been minimized.

Copy link
Contributor

commented Jun 12, 2017

Note that if we support listing timezones by default that complicates #20629. On the other hand, if we support #20629, maybe developers can use that and their own "list their source" instead of having listing be part of the standard time API.

@rsc

This comment has been minimized.

Copy link
Contributor

commented Jun 12, 2017

Will close this in favor of #20629.

@rsc rsc closed this Jun 12, 2017

@golang golang locked and limited conversation to collaborators Jun 12, 2018

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
You can’t perform that action at this time.