iansinnott / jstz

🌐Timezone detection for JavaScript
Other
175 stars 33 forks source link

Is JSTZ more reliable than Moment Timezone in detecting a user's timezone? #20

Open rohit103 opened 5 years ago

rohit103 commented 5 years ago

Hi, can you please comment on how JSTZ compares to Moment timezone in detecting user's timezone? I will greatly appreciate if you can compare about the reliability, browser, and OS support.

Thank you for creating such a helpful resource!

rohit103 commented 5 years ago

I found the following at Moment's website. Do you have any information like the following for JSTZ? Thank you!

Moment Timezone uses the Internationalization API (Intl.DateTimeFormat().resolvedOptions().timeZone) in supported browsers to determine the user's time zone.

On other browsers, time zone detection is rather tricky to get right, as there is little information provided by those browsers. For those, it will use Date#getTimezoneOffset and Date#toString on a handful of moments around the current year to gather as much information about the browser environment as possible. It then compares that information with all the time zone data loaded and returns the closest match. In case of ties, the time zone with the city with largest population is returned.

iansinnott commented 5 years ago

What I remember is that at the time moment timezone did not support detection. Maybe I missed it in the docs, but that's why I originally forked this lib. If you're already using moment and it does support that functionality perhaps this lib is unnecessary.

As for your second comment you can check out the source where the internationalization API is used (if present) here: https://github.com/iansinnott/jstz/blob/master/jstz.main.js#L102

As for whether moment is more reliable... Probably. I suppose you would have to see how this lib stacks up to their test suite which is certainly much more extensive.

rohit103 commented 5 years ago

Thank you @iansinnott for the prompt response and for making JSTZ!

On a different note, I will be sending you a note via an email soon. Best! Rohit