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 Android #20455

Open
tmm1 opened this Issue May 22, 2017 · 8 comments

Comments

Projects
None yet
6 participants
@tmm1
Copy link
Contributor

tmm1 commented May 22, 2017

initLocal() in zoneinfo_android.go is hard-coded to UTC:

func initLocal() {
// TODO(elias.naur): getprop persist.sys.timezone
localLoc = *UTC
}

func initLocal() {
	// TODO(elias.naur): getprop persist.sys.timezone
	localLoc = *UTC
}

x/mobile currently uses a hack to set time.Local for gomobile android apps (golang/mobile@730f563), but that predates the availability of tzdata on android (80b31c0).

cc @eliasnaur @crawshaw #13581 #10857

@bradfitz bradfitz added this to the Unreleased milestone May 22, 2017

@gopherbot

This comment has been minimized.

Copy link

gopherbot commented May 22, 2017

CL https://golang.org/cl/43754 mentions this issue.

@gwik

This comment has been minimized.

Copy link
Contributor

gwik commented Jun 26, 2017

Same issue on iOS, should I create a separate issue ?

@eliasnaur

This comment has been minimized.

Copy link
Contributor

eliasnaur commented Jun 26, 2017

Yes, create a separate issue and reference this one.

@tmm1

This comment has been minimized.

Copy link
Contributor

tmm1 commented Nov 6, 2017

Since I wasn't able to write a patch to fix this in golang, I ended up calling this from init() in my app instead:

func fixTimezone() {
	out, err := exec.Command("/system/bin/getprop", "persist.sys.timezone").Output()
	if err != nil {
		return
	}
	z, err := time.LoadLocation(strings.TrimSpace(string(out)))
	if err != nil {
		return
	}
	time.Local = z
}
@tmm1

This comment has been minimized.

Copy link
Contributor

tmm1 commented Apr 6, 2018

I found out there's a C api available for fetching properties, which should make it much simpler to support Android timezones from golang directly (via cgo): __system_property_get in <sys/system_properties.h>

My previous attempt in CL43754 was abandoned because it was too hard to call os/exec from the time package.

@eliasnaur

This comment has been minimized.

Copy link
Contributor

eliasnaur commented Apr 6, 2018

Good catch. If you mail a CL before the end of this month, it should be eligible for Go 1.11.

@tmm1

This comment has been minimized.

Copy link
Contributor

tmm1 commented Apr 6, 2018

Good catch. If you mail a CL before the end of this month, it should be eligible for Go 1.11.

I don't plan to submit any CLs, but others should feel free to do so.

You will need to first get a decision one way or another about whether the time package is allowed to depend on cgo, as originally proposed in #20797

@uudashr

This comment has been minimized.

Copy link

uudashr commented Jan 20, 2019

Do we have progress on this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment