moment-timezone
moment-timezone copied to clipboard
Incorrect Timezone guessed for UTC
On a Windows 10 laptop in IE 11 when running moment.tz.guess()
it returns "Africa/Abidjan" when the timezone is set to "(UTC) Co-ordinated Universal Time". On the same laptop in Chrome it correctly returns "UTC"
Running the following code produces the following outputs:
console.log((new Date()).toString());
console.log((new Date()).toLocaleString());
console.log((new Date()).getTimezoneOffset());
console.log(navigator.userAgent);
console.log(moment.version);
Internet Explorer 11 (London) undefined Fri Nov 10 2017 10:37:23 GMT+0000 (GMT Standard Time) 10/11/2017 10:37:23 0 Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; .NET4.0C; .NET4.0E; rv:11.0) like Gecko 2.19.1
Edge (London) Fri Nov 10 2017 10:39:42 GMT+0000 (GMT Standard Time) 10/11/2017 10:39:42 0 Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36 Edge/16.16299 2.19.1 undefined
Internet Explorer 11 (UTC) undefined Fri Nov 10 2017 10:42:32 GMT+0000 (Co-ordinated Universal Time) 10/11/2017 10:42:32 0 Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; .NET4.0C; .NET4.0E; rv:11.0) like Gecko 2.19.1
Edge (UTC) Fri Nov 10 2017 10:44:22 GMT+0000 (Co-ordinated Universal Time) 10/11/2017 10:44:22 0 Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36 Edge/16.16299 2.19.1 undefined
Yes, I can confirm this is a bug. It returns incorrectly in all browsers when the time zone is set to UTC on Windows.
Note that if you're actually in the UK, set your time zone to (UTC+00:00) Dublin, Edinburgh, Lisbon, London
, not to UTC. You should get Europe/London
correctly as a result on all browsers.
That's incorrect. In Chrome on Windows it returns 'UTC'. I know that the timezone has to be set to London and not UTC but customers who use my website dont know this and they are being stopped as my code checks for UTC and Europe/London only.
Is this bug going to be fixed?
Chrome gives Africa/Abidjan
for me when set to UTC on Windows. Either way, the bug is the same. Yes, I will look into this.
Note that if your customers are actually in London and have their time zone set for UTC, they are actually going to get the wrong time on their computer's clock when London is on British Summer Time.
Also, note that Africa/Abidjan
may not be quite as correct as UTC
, but it's still a pretty accurate guess, as Abidijan is a UTC+0 year-round time zone that has never had DST.
Any timings on when this will be fixed?
Any update on this issue? Thanks
I'm also experiencing this issue in Chrome, It gives Africa/Abidjan when window is set to UTC. Any updates\timing about this issue?
Thank in advance.
Just came across this when I upgraded to the latest release. I looked into it a bit, but I don't know the right resolution, so I'll just list my findings here and hope someone else more informed can finish it off.
from moment-timezone.js:
function rebuildGuess () {
// use Intl API when available and returning valid time zone
try {
var intlName = Intl.DateTimeFormat().resolvedOptions().timeZone;
if (intlName && intlName.length > 3) {
var name = names[normalizeName(intlName)];
if (name) {
return name;
}
logError("Moment Timezone found " + intlName + " from the Intl api, but did not have that data loaded.");
}
} catch (e) {
// Intl unavailable, fall back to manual guessing.
}
So it looks at Intl.DateTimeFormat().resolvedOptions().timeZone
and properly gets UTC. But the next line bails cause "UTC" is only 3 characters. I'm not sure why the test for >3 characters is here, so that's why I don't know what to do.
I would suspect this could fail for some other timezones like 'GB' or 'NZ' as well?
Anyways the code falls into manual guess mode where it looks like it's trying to compare offsets with known zones, and when you alphabetically sort all the zones that have the same timezone offset you're left with Africa/Abidjan as the first in the list.
Can the length test be dropped?
Just bumped into this. "UTC" fails in HeadlessChrome 71.0.3578.