Time Traveler plugin for Craft CMS 3.x
Allow users to change the time zone.
composer require matotominac/time-traveler
Time Traveler Overview
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.
Will this plugin work on already developed sites or are there any twig modifications necessary?
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.
Configuring Time Traveler
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.
Config file is not required, if you omit it all world timezones will be available for selection.
How to allow users to select the timezone in their profile:
- Create a new field of type TimeZone (this field type will be available when you enable the plugin). Plugin requires this field's handle to be set to
timeZonebut if you wish to have something different you will have to update the value of the option
time-traveler.phpconfig file (as shown in the snippet above).
- Add this newly created field to user's profile.
- That's all. Now every user is allowed to select custom timezone. Timezone for the user will be changed for both frontend site and Craft admin, as long as the user is logged in.
Time Traveler Roadmap
- Convert current field value instantly as user selects time zone from dropdown
- Frontend time zone selection for unregistered users
- Installation Instructions
To install this plugin, copy the command above to your terminal.
- Active Installs
- Last release
- July 1, 2021
- Activity (30 days)
- 0Closed Issues0Open Issues0Merged PRs0Open PRs