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: location data always falls back to UTC in js/wasm #28265

Closed
eternal-flame-AD opened this issue Oct 18, 2018 · 3 comments

Comments

Projects
None yet
3 participants
@eternal-flame-AD
Copy link

commented Oct 18, 2018

Please answer these questions before submitting your issue. Thanks!

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

go version go1.11.1 linux/amd64

Does this issue reproduce with the latest release?

Yes.

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

GOARCH="amd64"
GOBIN=""
GOCACHE="/home/ef/.cache/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/ef/code/go/"
GOPROXY=""
GORACE=""
GOROOT="/usr/lib/go"
GOTMPDIR=""
GOTOOLDIR="/usr/lib/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build929309457=/tmp/go-build -gno-record-gcc-switches"

What did you do?

Build and run the following snippet both in linux/amd64(local architecture) and wasm/js

package main

import (
	"fmt"
	"time"
)

func main() {
	fmt.Println(time.Now().Location())
}

What did you expect to see?

The results should be consisitent with the following javascript code, which should return the OS timezone info:

console.log(Intl.DateTimeFormat().resolvedOptions().timeZone)

What did you see instead?

On native architecture(linux/amd64):

Asia/Shanghai

On browser javascript:

Asia/Shanghai

On wasm:

UTC
@agnivade

This comment has been minimized.

Copy link
Member

commented Oct 18, 2018

zoneinfo_unix.go seems to contain js,wasm. Hence in a browser environment, it falls back to UTC. I think it should be possible to have a zoneinfo_js.go and call into wasm_exec.js to get the browser/node timezone.

@agnivade agnivade changed the title time: Unable to acquire timezone data in wasm/js time: location data always falls back to UTC in js/wasm Oct 18, 2018

@agnivade agnivade added this to the Go1.12 milestone Oct 18, 2018

@eternal-flame-AD

This comment has been minimized.

Copy link
Author

commented Oct 18, 2018

Yep, I think it require at least a bit of refactoring on the time package as the current infrastructure of the time package is not designed to handle handle timezone operations using syscall

@agnivade agnivade self-assigned this Oct 18, 2018

@gopherbot

This comment has been minimized.

Copy link

commented Oct 20, 2018

Change https://golang.org/cl/143577 mentions this issue: time: return correct zone info for wasm

@gopherbot gopherbot closed this in eef0140 Oct 24, 2018

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