Timezone issues in the backend

I might be overlooking something obvious, if so I apologise in advance.

I have a partial in my backend form with the following code:
<?= $formModel->roomOrderLine->start_time->format('l d. F Y') ?>

I’ve confirmed that the object is an Argon instance. But trying to manually force a timezone on the object like this does nothing.
<?= $formModel->roomOrderLine->start_time->tz('Europe/Oslo')->format('l d. F Y') ?>

The backend timezone for my current user is set to ‘Europe/Oslo’. All fields are stored as UTC in the DB with the app generally using Carbon toIso8601ZuluString as I’m also interfacing with Office365 calendars and external payment providers.

I have no issues with Carbon adhering to the right timezone in the frontend.

my config/app.php has this:
'timezone' => 'UTC',

my config/cms.php has this:
'timezone' => 'Europe/Oslo',

I’ve also tried forcing the backend timezone in config/backend.php to ‘Europe/Oslo’ but it seems to me the backend date settings are completely ignored.

My models in the backend are consistently ignoring timezone settings on all fields and in code as shown above. What could be the cause of this? It’s really just messing with my app since I cannot deliver it to a client in it’s current state. What am I missing?

Hey @egerstudio

Try the following for rendering on the user interface. This is how dates are rendered in the backend, and the conversion happens in JavaScript.

<?= Backend::dateTime($formModel->roomOrderLine->start_time, ['format' => 'l d. F Y') ?>

For server-side dates, it is correct that they are stored in UTC for consistency and translated using Carbon. The format you are using only displays the date so it might be necessary to include the time to see a difference. For example:

> \Backend\Models\User::first()->created_at->tz('Europe/Oslo')->format('l d. F Y H:i')
= "Tuesday 08. June 2021 17:37"

> \Backend\Models\User::first()->created_at->format('l d. F Y H:i')
= "Tuesday 08. June 2021 15:37"