gopherjs / gopherjs

A compiler from Go to JavaScript for running Go code in a browser
BSD 2-Clause "Simplified" License
12.61k stars 562 forks source link

Time.Format() local time zone in gopherjs does not match golang #923

Closed nathanhack closed 5 years ago

nathanhack commented 5 years ago

Hi, I was using time and needed the short form of the time zone. But it seems that gopherjs only does the long form.

What happened: https://gopherjs.github.io/playground/#/8x_apJ2hLw

What I expected: https://play.golang.org/p/6MlgfsMJ18W

I looked through the issues and I looked at the Gotchas but didn't see anything there. Maybe this is a known thing?

flimzy commented 5 years ago

GopherJS doesn't have access to the full timezone database, due to space restrictions. See here for details and discussion: https://github.com/gopherjs/gopherjs/issues/64

nathanhack commented 5 years ago

Thanks @flimzy, I initially saw that but dismissed it thinking I was only interested in "local" (which gopherjs sort of supports). Which led me to finding JS's toLocaleString() I thought oh this is probably just a missing options in gopherjs because I could easily do the following in JS:

var event = new Date(Date.UTC(2012, 11, 20, 3, 0, 0));
console.log(event.toLocaleString('default', { timeZoneName: 'short' }));
console.log(event.toLocaleString('default', { timeZoneName: 'long' }));

will output:

12/19/2012, 10:00:00 PM EST
12/19/2012, 10:00:00 PM Eastern Standard Time

But after looking at #64 in detail, I think my issue is related. :-( Maybe I'll use goment (an pure golang implementation of moment.js mentioned in #64) instead.