2

We are creating a small site to manage meetings that take place in many timezones. Administrators of the site will create meetings on behalf of teams everywhere. They may be in pacific timezone and receive a request to create a meeting from a team in England.

When creating the entry, the date/time they see if for pacific timezone, and to create the event with the correct time for GMT+1, they must do the math in their head as to what time in PST corresponds to the correct time in GMT+1.

Is it possible to have or add a field to specify which timezone the provided time is in, vs relying on the timezone set in settings?

1

I solved that by adding a dropdown field to user profiles where I allowed users to select timezone and then in custom module set the selected timezone like this:

class SiteModule extends Module
{
   public function __construct($id, $parent = null, array $config = [])
   {
       // Set correct Timezone
       $currentUser = Craft::$app->getUser();
       if ($currentUser) {
           $user = $currentUser->getIdentity();
           $timezone = null;
           if ($user->userTimeZone->value) $timezone = $user->userTimeZone->value;
           if ($timezone) {
               Craft::$app->setTimeZone($timezone);
           }
       }

       ...

If user is not logged in or does not have a timezone set Craft will use the system timezone for those users.

Timezone dropdown values are in the form 'America/Chicago'.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.