Hi,
I am using Samsung Galaxy S5 with newest chrome installed (Version 55.0.2883.91).
I switched to 'Asia/Shanghai' timezone (GMT+0800). This is China Standard Time - CST
However, moment.tz.guess() returns me 'America/Chicago' which is Central Standard Time - CST.
On Linux Mint, Chrome (Version 55.0.2883.87 (64-bit)) timezone is correct.
After digging a bit in the code, I figured out that the problem is that moment first tries to use information about timezone from: Intl.DateTimeFormat().resolvedOptions().timeZone which returns the wrong timezone on mobile. If I comment out detection from Intl guess() returns the right timezone.
From googling around I concluded that Intl stuff is still not too reliable. Could you add a flag for guess() so that it is possible to switch off detection through Intl?
My workaround:
import moment from "moment-timezone";
export default function guessTimezone() {
const supportsIntl = typeof global.Intl !== undefined;
let oldIntl;
let timezone;
// do not use buggy Intl for timezone guess
// See: https://github.com/moment/moment-timezone/issues/441
if (supportsIntl) {
oldIntl = global.Intl;
global.Intl = undefined;
timezone = moment.tz.guess();
global.Intl = oldIntl;
} else {
timezone = moment.tz.guess();
}
return timezone;
}
Sorry for the late reply, but yeah, that's a pretty reasonable enhancement request.
@maggiepint , I have the same issue on Linux mint 18 & chrome Version 57.0.2987.110 (64-bit).
Any updates?
Got the same issue.
moment.tz.guess() returns'UTC' for me on Ubuntu 16.04 using Chrome Version 57.0.2987.133 (64-bit).
I expected it to return 'America/New_York'
I encountered this issue too, on Chrome 60, 61 for Mac, I found if I switch timezone to another timezone and then switch back, Intl.DateTimeFormat().resolvedOptions().timeZone will return the correct value. But new Date().getTimezoneOffset() will be 0...
@bolasblack something like RangeError: Expected Area/Location(/Location)* for time zone, got Etc/GMT+7? I expect it to be 'America/Phoenix'. How do I fix?
Dup #423
Most helpful comment
My workaround: