jsTimezoneDetect
Categories
Component ID
Component name
Component type
Maintenance status
Development status
Component security advisory coverage
Component created
Component changed
Component body
I needed a simple way to detect a user's timezone in order to display dates in their local timezone without depending on their user profile to save the correct timezone. An existing module, Timezone Detect, implements a Javascript library known simply as "jsTimezoneDetect," which did the job. The difference is that, while Timezone Detect saves the detected timezone to the user account, I'm dealing with shared user accounts for universities and other organizations whose students might belong to multiple timezones.
This library simply defines the "jstz" library, adds a Drush integration to automatically download the minified JS for it, and adds Javascript to each page that will detect the user's timezone and assign it to the javascript variable Drupal.settings.jstz.
Note: in order to use this variable, you may need to manually call Drupal.behaviors.jstz.attach(context, settings); in order to make sure that Drupal.settings.jstz has been set before running your own code. If there is a better way to accomplish this, I would be more than happy to hear it!
