'Octobercms timezone issue

I am trying to set the timezone in OctoberCMS to South African Standard Time (SAST), I have tried editing app.php with time zones CAT, SAST, UTC+2 and UTC+2:00 but none are accepted so I am unsure how to get the system to display the correct time.

/*
  |--------------------------------------------------------------------------
  | Application Timezone
  |--------------------------------------------------------------------------
  |
  | Here you may specify the default timezone for your application, which
  | will be used by the PHP date and date-time functions. We have gone
  | ahead and set this to a sensible default for you out of the box.
  |
 */
'timezone' => 'UCT',


Solution 1:[1]

Just struggled with something similar. Here was my final setup. Shared server is running on "MST" as was MySQL by default

Config Files:

app.php

...
'timezone'=>'UTC',
...

database.php

...
'mysql'=>[
    'timezone'=>'-00:00',
    'driver'=> ...
]

Backend: user can pick their timezone in their individual preferences. I chose 'UTC' for checking that everything was time stamping correctly.

Frontend: Need to convert to users TZ for presentation and forms. Your save process must convert from User TZ to 'UTC'. You can use JS to get the user TZ from browser and AJAX it to your server for saving a session variable or other method of telling server what TZ the user is using.

<script>
tz = Intl.DateTimeFormat().resolvedOptions().timeZone;
window.addEventListener("load", function(){
$.request('onSetTZ', { data: {tz: tz}});
});
</script>

You can convert TZ in twig but I suggest that you handle all TZ conversions in PHP using Carbon for retrieval, presentation and saving because it will be easier if this is done all at the same layer.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 firemankurt