-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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 function to generate a Location struct #20629
Comments
You're jumping to a solution here.
Is that the actual problem? If so, we can discuss that problem.
We definitely don't want any types or zone constructor functions in the time package. If we're going to add a new package, I'd rather see something like In any case, I'm against your proposed solution. But maybe you want to restate the problem. (Please don't edit the top comment, though.) |
Not surprised, I am not too happy about the proposal either. I'm thinking about portability and custom locations. If I understand the current situation correctly (not 100% sure about that after your reply), the return values of LoadLocation depend on the local zonefile, which may be outdated for example. |
What do you mean by portability? And what is a custom location? Is there missing data in tzdata?
What is the GopherJS bug URL for this issue? I'm curious what the options to address it are. Presumably they can just bundle the whole tzdata zip file into the Javascript if they really wanted everything. But perhaps that's too big. |
By portability I mean the possibility of writing code that involves time.Location instances and produces the same results independent of environment details (like OS, version/presence of tzdata). Note: Countries/states change daylight saving details quite quickly sometimes. So tzdata being out of date is not as weird as it may sound. The GopherJS issue is gopherjs/gopherjs#64. Yes, size is a problem that is interesting. A size efficient solution that was discussed years ago is using momentsJS as a source of location data. |
We definitely don't want to expose Zone, ZoneTrans, and so on. Location is where the API stops. I do understand wanting to get the location info from somewhere else (a []byte in tzdata format), but the solution would be an API solving that problem. |
Note that any solution here should probably address #20211 as well (closed as dup of this one). The theory is that if you can override where location data comes from, the override can provide its own listing function separate from package time. |
That sounds a lot better. So I guess a solution to both issues could look like this? Looking at the code this should be a tiny patch. I'm happy to submit some code if everyone is happy with this. Btw.: What's the deal with not importing os (mentioned in #20211)? Is that a general rule? |
Packages in standard library have tiers, and higher level tiers are not allowed to import lower level ones. This is to prevent import cycles, and per policy, to keep package size smaller. See here for full details. |
We're not sure what the API here should be. Does anyone want to make any suggestions? |
Looking for clarification/confirmation, but what would be the uses/users of this new API? Is it needed by anyone/anything other than to resolve the underlying mentioned GopherJS issue? Because I'm quite confident the GopherJS issue could be resolved by modifying the |
What about the scenarios outlined above? |
The signature looks right, but the name is probably not specific enough to the problem being solved. It's nice if this begins with Load to match LoadLocation. |
Yes, I would even suggest keeping both words in |
OK, let's run with |
Change https://golang.org/cl/68890 mentions this issue: |
I think we should call it LoadLocationFromTzinfo, because TZData sounds like the file used on Android. |
I think we should stick with tzdata. www.google.com/search?q=tzdata vs www.google.com/search?q=tzinfo seems to show clearly that tzdata is the much more common term. (tzinfo seems to be very popular in ruby?) I don't think enough people know about this detail of Android to cause serious confusion. |
I don't want to go overboard with the bikeshedding, but since we'll be stuck with that name let me add this one comment before I resend the CL.
https://www.ietf.org/timezones/tzdb/tzfile.5.txt says this about the format:
If you want to go for tzdata, please tell me if you prefer |
But nobody really says tzfile either. I suppose it could My comment about the capitalization was about the use of |
Change https://golang.org/cl/79176 mentions this issue: |
Tzinfo was replaced with TZData during the review of CL 68890, but this instance was forgotten. Update it for consistency. Follows CL 68890. Updates #20629. Change-Id: Id6d3c4f5f7572b01065f2db556db605452d1b570 Reviewed-on: https://go-review.googlesource.com/79176 Reviewed-by: Brad Fitzpatrick <[email protected]>
Since the implementation of this issue is supposed to address #20211, I think it would make sense to make loadTzinfoFromZip an exported method as it is nontrivial to implement if someone wants to use a specific zoneinfo.zip file as their source of truth for time zones. The alternative seems to be to unzip the zoneinfo file and use a directory instead of a zip, which makes reading the correct location file much easier. Either way, the path to using a specific version of the IANA time zone database reliably is still far from clear in my opinion. |
If I am not mistaken it is currently not possible (without using unsafe) to generate a time.Location. This is a bit of a problem because whether LoadLocation works is quite pretty platform/instance dependent. A simple solution could be to add:
func NewLocation(name string, zone []Zone, tx []ZoneTrans) *Location
which would require making Zone(Trans)? and theyr fields public.
I guess Zone and ZoneTrans could also go into a subpackage to avoid cluttering the documentation of the time package.
The text was updated successfully, but these errors were encountered: