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

Incorrect Timezone guessed for UTC #559

Open
rstalbow opened this issue Nov 10, 2017 · 8 comments
Open

Incorrect Timezone guessed for UTC #559

rstalbow opened this issue Nov 10, 2017 · 8 comments

Comments

@rstalbow
Copy link

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

@rstalbow rstalbow changed the title Incorrect Timezone in IE 8 Incorrect Timezone in IE 11 Nov 10, 2017
@mattjohnsonpint mattjohnsonpint changed the title Incorrect Timezone in IE 11 Incorrect Timezone guessed for UTC Nov 10, 2017
@mattjohnsonpint
Copy link
Contributor

mattjohnsonpint commented Nov 10, 2017

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.

@rstalbow
Copy link
Author

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?

@mattjohnsonpint
Copy link
Contributor

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.

@rstalbow
Copy link
Author

Any timings on when this will be fixed?

@gregoryhudson
Copy link

Any update on this issue? Thanks

@yoniab
Copy link

yoniab commented Jun 4, 2018

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.

@chrisregnier
Copy link

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?

@jmullo
Copy link

jmullo commented Jan 10, 2019

Just bumped into this. "UTC" fails in HeadlessChrome 71.0.3578.

rahulwakadeION pushed a commit to iongroup/moment-timezone that referenced this issue Jul 23, 2021
- Removed guessed timezone length check in order to treat "UTC" as valid timezone(moment#559)
- Updated version to 0.6.33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants