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"

Thank you, this works for the partials I was having issues with.

But another related problem arises when I try to edit times for opening hours.

(Sorry, can’t upload more than one screenshot apparently, but my column view shows opening and closing hours one hour later than the fields do. In this case 08:00 opening and 21:00 closing)
In column view the correct time is displayed, and its set up like this:

open:
    label: Åpningstid
    type: datetime
    format: H:i
close:
    label: Stengetid
    type: datetime
    format: H:i

But when I go to edit I get fields that are not taking the current timezone into account:


The fields are defined as such:@

open:
    label: Åpningstid
    mode: time
    span: left
    type: datepicker
    useTimezone: true
close:
    label: Stengetid
    mode: time
    span: auto
    type: datepicker
    useTimezone: true

What am I doing wrong? The open and close fields I’ve tried storing as both datetime and timestamp in the database, but that doesn’t seem to change anything either.

Any help would be greatly appreciated, timezones and times are a pain :wink: