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

time: time.Local is always UTC on iOS #20797

Open
gwik opened this issue Jun 26, 2017 · 11 comments
Open

time: time.Local is always UTC on iOS #20797

gwik opened this issue Jun 26, 2017 · 11 comments
Labels
Milestone

Comments

@gwik
Copy link
Contributor

@gwik gwik commented Jun 26, 2017

Local timezone is hardcoded to UTC on iOS.

https://github.com/golang/go/blob/master/src/time/zoneinfo_ios.go#L39-L42

func initLocal() {
	// TODO(crawshaw): [NSTimeZone localTimeZone]
	localLoc = *UTC
}

As mentioned in the code it should use NSTimeZone localTimeZone to get the current timezone.

cc @eliasnaur @crawshaw

(Same issue on android #20455)

@gwik
Copy link
Contributor Author

@gwik gwik commented Jun 26, 2017

I'll work on it next week.

@ALTree ALTree added this to the Go1.10 milestone Jun 26, 2017
@gwik
Copy link
Contributor Author

@gwik gwik commented Jul 2, 2017

This adds a dependency to cgo in the time package which is against policy enforced by go/build/deps_test.go and breaks the test.

@bradfitz
Copy link
Contributor

@bradfitz bradfitz commented Nov 15, 2017

I'd rather avoid modifying the policy for certain ports.

Maybe we can put this in another package (runtime?) and use it from time. That's kinda gross too, though.

@rsc, preferences?

@rsc
Copy link
Contributor

@rsc rsc commented Nov 22, 2017

Not this cycle.

@rsc rsc modified the milestones: Go1.10, Go1.11 Nov 22, 2017
@tmm1
Copy link
Contributor

@tmm1 tmm1 commented Apr 6, 2018

Pinging for a decision on how to proceed here.

@bradfitz
Copy link
Contributor

@bradfitz bradfitz commented Apr 6, 2018

@tmm1, I'm not sure anybody's thought about it.

It'd be nice to see something that works first, and then we can see how gross it ends up, and where we might shove that grossness. Or maybe it'll look fine.

/cc @eliasnaur @bcmills

@tmm1
Copy link
Contributor

@tmm1 tmm1 commented Apr 6, 2018

@gwik It sounded like you had a patch for this which was breaking deps_test.go. Care to open a CL with it?

@bradfitz bradfitz added the mobile label May 30, 2018
@bradfitz
Copy link
Contributor

@bradfitz bradfitz commented May 30, 2018

/cc @eliasnaur too

@bradfitz bradfitz modified the milestones: Go1.11, Unplanned May 30, 2018
@bradfitz bradfitz added the NeedsFix label May 30, 2018
@mmaxim
Copy link

@mmaxim mmaxim commented Jun 24, 2019

Ping for this issue, curious if anyone has thought about it, or if it is just lost. It's not the end of the world (can just call the right functions directly), but would be nice for Go to do something more useful on these platforms.

@clwr
Copy link

@clwr clwr commented Dec 11, 2019

It is disappointed that this is still an issue since two years.
I have to fix it by myself to get the correct time. Here is my solution.

import (
	"time"
	"ObjC/Foundation/NSTimeZone"
	"strings"
)


func fix() {
	NSTimeZone.SystemTimeZone()
	z, _ := time.LoadLocation(strings.Split(NSTimeZone.SystemTimeZone().Description()," ")[0])
	time.Local = z
}

Hope Gomobile can be better in the future.

@eliasnaur
Copy link
Contributor

@eliasnaur eliasnaur commented Dec 11, 2019

The correct fix is not as easy as it sounds because of cgo restrictions, see above. One easier workaround is to do the timezone setting on gomobile itself, not the Go runtime. I encourage anyone interested in fixing this issue to try that, if for nothing else than the runtime fix will not be released until Go 1.15 in August next year.

That said, @gwik's original approach might be feasible without Cgo now that Go uses libc on Darwin.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
8 participants
You can’t perform that action at this time.