top | item 6175157

Stop asking users for their timezone – use per-device settings and JavaScript

96 points| neilk | 12 years ago |trevoro.net | reply

64 comments

order
[+] kintamanimatt|12 years ago|reply
This pretty much breaks progressive enhancement. If anything, the user's time zone should be first estimated from their IP address with a setting to override it. The client side solution to further refine it should be piled on top of this last, if possible. JavaScript is useful, but nobody should assume it's present.

Also, it should be noted which time zone a time is in. A naked date/time is about as useful as saying that you're 3 units away from me. What unit does "unit" represent? shrug

[+] trevoro|12 years ago|reply
By your logic I'd be running a WAP site over Gopher to satisfy the progressive enhancement ethos. At a certain point it's absurd to assume javascript isn't there. [1]

What brought on this particular use case was a JSON response where all the times were in UTC. I'm not really into forcing a technique on someone when it isn't required. If that's not your use case, then you don't have the problem!

[1] http://www.mozilla.org/en-US/firefox/23.0/releasenotes/

[+] crazygringo|12 years ago|reply
1) Exactly. This doesn't help at all with server-side rendering of times, which is usually the use-case (times associated with forum comments, etc.). IP address detection is pretty annoying to do (and doesn't help with VPN's etc.), but a quick <script> in the <head> of any page that does an instant "redirect" to put the JavaScript timezone info into a server-side session variable is a functional, albeit hackish, solution. (If you don't have JavaScript enabled, then just serve up UTC times, it's an edge case.)

2) Usually your times are stored server-side in UTC, so you never have to worry about timezones anywhere. It simplifies things a great deal. "Naked" = UTC. You assume that, whenever it's stored, it's already been translated from the user's timezone when the date was initially generated, or else the time it happened on the server was the actual time.

[+] TazeTSchnitzel|12 years ago|reply
Progressive enhancement of dates is easy. Output UTC, update to local time zone with JS. Simple!
[+] lvturner|12 years ago|reply
An option to override this is a must, I frequently use VPNs and as a result appear in many different countries through-out the day - It's bad enough with google repeatedly blocking my accounts for suspicious logins, without having to worry about timezone differences too.

Also, it'd be nice to ALERT me when my timezone has changed and give me an option to keep the old one, or use what you think my current one is.

[+] hrktb|12 years ago|reply
In this case progressive enhancement is offering a GMT date or other sensible default, and offer another date after javascript kicks in.

Personaly, I think for anything where timezone is relevant, the best move is to always let the user manually enter the timezone he/she wants, or have it match the timezone of the event/service he's looking for, and of course allow for override, so changing timezone has to done client side.

I.e. if I am in Germany and search from a flight taking off from Taipei two days from now, I don't care about the departure time from the German timezone. Same thing if I reserve a restaurant in Germany while I am in Taipei, you'll want the german time for the reservation. For something internationally broadcasted showing the UTC time as default and provide a way to adapt to other timezone is OK, as the event has no local anchoring anyway.

People can do the calculation for timezones, eventually some opt to not change their phones timezone to keep in sync with other more important schedules, etc. Trying to do 'smart' things seamlessly is often just screwing with the user.

[+] eli|12 years ago|reply
Geolocating the timezone based on IP is so fragile and likely to fail that IMHO it's not nearly worth the time to implement.
[+] DigitalTurk|12 years ago|reply
Oh, I hate when website follow your approach.

To start, it doesn't work if you use VPNs. Second, it doesn't update when you travel.

Here's one example. Even though I'm logged into Google and used Google Maps' 'pinpoint my location' feature, Google Reader is currently emailing me my daily schedule (a feature I enabled recently) in the afternoon. That's also despite my appointments being annotated with timezone information.

I call this bad engineering.

[+] amiruci2|12 years ago|reply
I looked into getTimezoneOffset when implementing pre-orders here at Gumroad and realized that technically this is incorrect:

"Luckily, the browser already knows what timezone the user is currently in, so we can make use of the getTimezoneOffset() function"

Getting the timezone offset isn't the same as getting the timezone. Granted that in certain cases having the offset is good enough, but sometimes you need the actual timezone. In my example I needed to know when a merchant wants their pre-order to be released. For that to work predictably I needed to know their exact timezone in order to adjust the time for daylight saving properly. Remember that there are quite a few timezones that are UTC-7 and they can behave differently in regards to daylight saving.

[+] tjoff|12 years ago|reply
Fortunately operating systems on laptops and mobile devices all adjust timezones automatically whenever they connect to the internet.

My laptop has never changed timezone automatically. And that is a feature in my eyes.

How can you assume that just because I'm doing a weekend trip that I want my whole life to be centered around the timezone in that particular place?

[+] crazygringo|12 years ago|reply
Most people want their clocks to be correct, local time, including their laptop clock. It's a better assumption to make for most people.

Of course, it can always be turned off for others, like yourself! :)

[+] dan_sim|12 years ago|reply
I wrote a javascript library that detects the standard time, the daylight saving time for the current time zone : https://github.com/dsimard/timezonedetect

Garry Tan, cofounder of posterous, said of it : "Finally, timezones in javascript done right. The world has been made a better place via this fine javascript library."

[+] btipling|12 years ago|reply
I want to agree, but there are times when you have to ask for timezones, like when you want to collect and present data in discrete time units like days. If a user wants to know how many app installs they have per 'day', you have to know what time the time the day they care about begins and ends before you start dumping data into those time delineated buckets. It's not always the timezone their browser uses. Especially not with agencies that are providing these services for clients that are somewhere else.
[+] icebraining|12 years ago|reply
UTC, not GMT.
[+] dfc|12 years ago|reply
I had the same reaction. Whenever I read GMT I know instantly that the author is not a big time nut and to take the rest with a grain of salt...
[+] dspillett|12 years ago|reply
> Luckily, the browser already knows what timezone the user is currently in

Incorrect (though usually true, I'll grant). I've often seen people with older Windows laptops (newer Windows variants, 7 and 8 certianly Vista maybe, are much better at this) that are set to display UK time but think that they are in UTC-0700. This can be fun when using file synchronisation tools... If the OS doesn't know its timezone then the browser won't either. This is a moot point when you are talking to just one user, until that user fixes their clock settings of course, but becomes a significant issue as soon as you need to coordinate timed actions between users.

Detecting the local time offset from your reference clock isn't always useful either: the machine's clock could be completely wrong so it says 01:23 where the user's wall-clock says 21:00 and your reference time matches neither.

Also some users may wish to fix your interface to a timezone other than the one currently set on the device they are currently using. Someone on holiday or on a business trip might want to keep some things linked to local time back home so they find it easier to coordinate with people there. Conversely someone currently in their home timezone might want to force your interface to match a non-local timezone for coordinating with teams/friends elsewhere in the world. You can't rely on them adjusting their clock in this circumstance as they may not be using their own machine and so might not be able to adjust the time/timezone settings (or may wish to keep them accurate to current local for other reasons).

tl;dr: Dealing with time values when there are any international concerns it harder than we tend to assume.

[+] jenseng|12 years ago|reply
UTC offset is well and good if you are talking about today, but as soon as you start displaying past or future datetimes, DST will bludgeon you over the head.

And depending on your app, users might want control over the timezone. When a teacher creates an assignment in canvas-lms, the due date defaults to midnight of the selected day. It would be surprising if it set it to 2am, just because the teacher happened to be traveling when the assignment was created.

[+] excitom|12 years ago|reply
Exactly. I have run into this problem with event calendars. For example: Schedule a recurring event for 1pm. It happens to be EDT at the moment so you store the event date/time in UTC by adding 5 hours. Then, in days, weeks, or months, we change to EST. The 1pm meeting is now showing at noon.

To fix this I run a cron job on the ST/DT boundaries that increments or decrements stored date/times in the event calendar.

[+] anigbrowl|12 years ago|reply
While we're at it, why (if I'm in the US) do I have to keep selecting my state, town etc., in addition to my zipcode?
[+] pg_bot|12 years ago|reply
It depends on the application that you are working on. The more you rely on geographic information the more strict you must be. So let's review why you need all that info. If you don't include the zipcode with all the rest of your information, you run into the Washington Township problem. http://en.wikipedia.org/wiki/Washington_Township

You can't infer (reliably) your exact location from a zipcode because of the reasons listed in the other comments linked to your parent comment.

[+] JSadowski|12 years ago|reply
Because zip codes do not equate to cities 1 to 1. Many cities have multiple zip codes, and some zip codes span multiple cities.

Zip codes are based on postal routes, cities are not.

[+] eric_the_read|12 years ago|reply
ZIP codes can be shared among multiple towns. Quite possibly multiple states, though I can't think of an example offhand.
[+] joevandyk|12 years ago|reply
It's less work for the developers, who might have more important things to do?
[+] rustynails|12 years ago|reply
If you do localise content, make sure it's what your users want.

When it comes to Rotten Tomatoes, I'm glad it asks my location because I prefer US film reviewers to my local film reviewers. If I let Rotten Tomatoes know my time zone, I can't access US reviewers (that I'm aware of).

[+] sigsergv|12 years ago|reply
Timezone — is not just offset! Proper use of timezones is not so simple unfortunately. And browser usually doesn't provide correct timezone name that could be used reliable (like Europe/Berlin).
[+] taylodl|12 years ago|reply
It seems most people resort to storing time in UTC, but this isn't your only option: any fixed time zone will do. If you're in a corporate setting and the majority of your users are in the same time zone as your servers, then it makes sense to use that time zone. There's fewer date conversions that way. For half the year there will be basically no conversions and for the other half it's a 1 hour DST conversion - which many time handling libraries have optimized (I'm in the United States in an area that observes DST for half the year).
[+] TazeTSchnitzel|12 years ago|reply
>any fixed time zone will do.

Theoretically, yes. In practice, you should just use UTC.

>If you're in a corporate setting and the majority of your users are in the same time zone as your servers, then it makes sense to use that time zone.

No it doesn't. Use UTC. The Internet does not have a time zone.

>There's fewer date conversions that way.

Your library is probably "converting" the date anyway, UTC or not.

>for the other half it's a 1 hour DST conversion - which many time handling libraries have optimized

Is it really that slow to convert a date?

[+] apaprocki|12 years ago|reply
Storing datetimes in fixed timezones that do not observe DST will do (but it is still not recommended), but you can't say any fixed timezone will do. Say you're storing datetimes in EST/EDT and you have a global audience. On the day the US goes back to standard time, how do you know whether 1:30AM in your database is the "first" 1:30AM or the "second" 1:30AM when you need to display the event to someone in Dubai? Are you going to store some extra metadata to indicate whether DST was in effect beside the datetime? Just store UTC.
[+] dalore|12 years ago|reply
GMT? Surely they mean UTC as GMT is no longer precisely defined by the scientific community.