Make WordPress Core

Opened 10 years ago

Last modified 3 years ago

#28988 new enhancement

Detect Time Zones automatically at installation

Reported by: danielmount's profile danielmount Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version:
Component: Date/Time Keywords: dev-feedback needs-patch
Focuses: javascript Cc:

Description (last modified by georgestephanis)

Currently, upon installing WordPress, one of the steps I always take is to go to Settings > General > Timezone to manually set my time zone. I've been using Wordpress for eight years, so I know to do it and how to do it, and it's just a minor inconvenience. However, I have seen people new to this platform be confused and/or not know how to change this.

Is it technologically possible to use a geolocation service to query the IP address of the computer installing Wordpress and automatically set that service's best guess as to time zone, perhaps during the setup process?

I would envision the UI option remaining in settings, in case, for example, a developer in one time zone builds a site for a client in another. But automatic detection would be perfect for the average new user. It would be one more element that just works out of the box for those who aren't particularly tech savvy.

I did some searching in Trac to see if I could find a similar ticket and couldn't find any.

Change History (10)

#1 @michalzuber
10 years ago

  • Keywords dev-feedback added
  1. We could set timezone according to selected language #28577
  2. With JS jstimezonedetect

#2 @danielmount
10 years ago

I like option 2. With option 1, it would work for some languages, but English and Spanish are spoken worldwide, and Chinese and Russian span a wide number of time zones as well.

#4 @ocean90
10 years ago

#29394 was marked as a duplicate.

#5 @chriscct7
9 years ago

  • Keywords needs-patch added

#6 @curdin
8 years ago

Is this a nicety worth 43 kb (12 kb compressed) in js libs? It might be better to see this as a progressive enhancements seeing that Intl is now more widely available http://caniuse.com/#search=Intl (although whether timezone detection is working correctly is TBC)

Last edited 8 years ago by curdin (previous) (diff)

#7 @dd32
8 years ago

  • Focuses javascript added

It looks like we'll be able to use Intl.DateTimeFormat().resolvedOptions().timeZone here now.

It's supported by recent Chrome & Safari, Firefox 52 will support it (Currently in the Developer channel), however IE is likely not implementing it. Progressive enhancement to support it when possible seems like a good option to me.

I'm unsure of what UI it should have though, transparent in the background? option to select timezone hidden behind a Timezone: Australia/Brisbane [change] section, etc.

#8 @danielmount
8 years ago

I favor the option to select a timezone hidden behind a timezone selected by default.

Selecting the admin's time zone automatically should be correct in most cases, but I can think of several exceptions where ability to change would be useful, e.g. a developer in one time zone building a site for an organization in another, or a website being built through a VPN in a country with restricted Internet access, like China.

#9 @georgestephanis
3 years ago

  • Description modified (diff)

Just did some minor tinkering and here's some prototype code (would obvs needs translations and such, but it works --

(function($){

	// This may need some browser support checks to make sure it's there --
	// https://caniuse.com/mdn-javascript_builtins_intl_datetimeformat_resolvedoptions_computed_timezone
	const browserTz = Intl.DateTimeFormat().resolvedOptions().timeZone;
	const $tzSelect = $('#timezone_string');

	if ( $tzSelect.val() !== browserTz ) {
		$tzSelect.after( '<p>Your browser timezone is currently set to <code>' + browserTz + '</code> -- <a class="updateTzSelectToBrowser" href="#">would you like to update the WordPress timezone to match?</a></p>' );
		$tzSelect.parent().find('.updateTzSelectToBrowser').on( 'click', function(e){
			e.preventDefault();
			$tzSelect.val( browserTz );
			$(this).parents('p').text('Updated!').fadeOut('slow');
		})
	}

})(jQuery);

My gut feeling is it'd be easier to add here to save someone scrolling through the massive dropdown, but totally doable to populate via js in the install flow if we wanted there as well.

Definite +1 to getting something along these lines in.

Last edited 3 years ago by georgestephanis (previous) (diff)

This ticket was mentioned in Slack in #core-datetime by georgestephanis. View the logs.


3 years ago

Note: See TracTickets for help on using tickets.