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: add Location.Zone method? #20091

Closed
tnclong opened this issue Apr 24, 2017 · 3 comments
Closed

proposal: time: add Location.Zone method? #20091

tnclong opened this issue Apr 24, 2017 · 3 comments

Comments

@tnclong
Copy link
Contributor

tnclong commented Apr 24, 2017

Please answer these questions before submitting your issue. Thanks!

What version of Go are you using (go version)?

1.8

What operating system and processor architecture are you using (go env)?

mac OS

What did you do?

I found method Zone() on time.Time that get the zone name and zone offset second.
I want get the same things from time.Location.

Do you consider add a Zone() method to time.Location ?
It's also really better that we can get a method Offset(*time.Location) in time.Location

Thanks for your reply.

@bradfitz bradfitz changed the title time.Location support Zone() and Offset(*time.Location) time: add Location.Zone method? Apr 24, 2017
@bradfitz bradfitz changed the title time: add Location.Zone method? proposal: time: add Location.Zone method? Apr 24, 2017
@gopherbot gopherbot added this to the Proposal milestone Apr 24, 2017
@ALTree
Copy link
Member

ALTree commented Apr 24, 2017

Each Location can have multiple timezones so that would have to be Zones (not Zone), returning a slice of zonenames. Same for offsets. For example Europe/Rome has [CET, CEST].

Keep also in mind that the set of timezones used in a Location can change over time, so I'm not so sure it would make sense to add a Zones method to Location.

@ianlancetaylor
Copy link
Contributor

@tnclong It would help if you could provide an example for how you would want to use this.

Note that Location already has a String method that returns the descriptive name.

@rsc
Copy link
Contributor

rsc commented May 15, 2017

The zone name and zone offset in use depend on exactly what time it is. That's why time.Time has the method and not time.Location. We could add a method on Location where you pass in a time, but then instead of loc.ZoneFor(t) why not do t.In(loc).Zone()?

(This is also why Location is called Location and not time.Zone.)

@rsc rsc closed this as completed May 15, 2017
@golang golang locked and limited conversation to collaborators May 15, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants