Allow users to change the time zone.
This plugin requires Craft CMS 3.0.0-beta.23 or later.
To install the plugin either install it through Plugin Store or tell Composer to load the plugin and then go to Settings → Plugins and click the “Install” button for Time Traveler.
composer require matotominac/time-traveler
With Time Traveler plugin users will be able to select a timezone for their user account. When they select a timezone all dates will instantly be shown in their selected time zone, no need for any extra frontend conversion. Also everything they post that includes time will be posted in their time zone and propery converted to system's time zone.
When you enable the plugin all timezones will be available in the dropdown but you are in total control of selecting which timezones will show and you can also rename timezones to something nicer than default PHP timezone labels.
Create a file called time-traveler.php
in your Craft's config folder and paste the following code.
<?php
return [
'*' => [
'timezoneList' => [
'America/New_York' => 'Eastern Time',
'America/Chicago' => 'Central Time',
'America/Denver' => 'Mountain Time',
'America/Phoenix' => 'Mountain Time (no DST)',
'America/Los_Angeles' => 'Pacific Time',
'America/Anchorage' => 'Alaska Time',
'America/Adak' => 'Hawaii-Aleutian Time',
'Pacific/Honolulu' => 'Hawaii-Aleutian Time (no DST)',
],
'fieldName' => 'timeZone'
],
];
timezoneList
option has the form '[php time zone name]' => '[label]'
. List of all PHP time zones can be found here.
Two sample config files for US and Australian time zones are included in plugin's root folder, you can directly copy them to your Craft's config folder. Please do not forget to rename them to time-traveler.php
.
To allow users to select timezone follow these steps:
timeZone
but if you wish to have something different you will have to update the value of the option fieldName
in your time-traveler.php
config file (as shown in the snippet above).Yes, this plugin will work on any already existing site. All you need to do is enable the plugin, add the field to user's profile as described below and that's it, plugin will work out of the box, even on existing sites. No modifications are necesary in twig code for showing dates on frontend.
Absolutely. Time zone selection field is a field like any other custom field on user profile. Simply add the dropdown field with list of timezones and name it fields[timeZone]
(or replace timeZone
in case you renamed the field as shown above).
Unfortunately not yet but that feature is on our roadmap.