Was looking at this tutorial here http://pellepim.bitbucket.org/jstz/ on automatic timezone detection using javaScript which detects the device's time zone setting.
I was wondering if anyone had any idea (ballpark is fine) of how accurate this method is of detecting timezones?
Thanks for your time!
I cannot speak to how accurate this specific library (jsTimezoneDetect) is, but assuming that the library is using the native «Date().getTimezoneOffset()» method and simply has a lookup table to return the correspoding timezone...and the lookup table is correct, then this will be a pretty robust way of doing it.
From the Mozilla documentation:
From the "limitations" section of the project page:
You can see several issue where detection is imperfect in the project's issue tracker.
From a design perspective, it's attempting to do the right thing by taking several readings at different points in time using
getTimezoneOffset()
and comparing them against known values.The biggest problem is that JavaScript lies. It's API would make you think you could check for the local offset of any date/time. But in reality, it only knows about the current rules for the time zone. Since different time zones change at different points in time, it's very difficult to know whether or not you are working with the "current" time zone rules unless you are specifically checking "now". This was brought up in issue #68, but was decided to be out of scope.
Also consider that if you're only testing the current rules, there are often several different time zones that overlap. See issue #74 and issue #64.
As time zone rules change over time, new versions of jstzDetect will have to be released to compensate. Apps that use it will have to plan on updating as well. So far, there haven't been many updates.
Unfortunately, there is not a perfect way to detect the user's time zone. Some browsers are starting to support the following built-in mechanism:
But it's not widely adopted yet, and unfortunately there are bugs there too.
The best advise I can offer is to use jstzDetect as a starting point. It's good at making an initial guess for some other time zone selection control in your application. If you care about accuracy, don't use it for more than that.
See also, this related answer.