kimai / Paid-plugins

Support for paid Kimai plugins: Discussions and feature requests
https://www.kimai.org/store/
11 stars 1 forks source link

Fatal error on "Date and Time" field #98

Closed Jelle-S closed 1 year ago

Jelle-S commented 1 year ago

When adding a Date and Time field to an activity, we get a fatal error on the edit screen of an activity, with following message:

request.CRITICAL: Uncaught PHP Exception Exception: "DateTimeZone::__construct(): Unknown or bad timezone ()" at [...]/src/Form/Type/TimePickerType.php line 62 {"exception":"[object] (Exception(code: 0): DateTimeZone::__construct(): Unknown or bad timezone () at [...]/src/Form/Type/TimePickerType.php:62)"} []

When I remove the field again, the error is gone too.

kevinpapst commented 1 year ago

You need to debug which timezone is used in that place: https://github.com/kimai/kimai/blob/main/src/Form/Type/TimePickerType.php#L62

This is not a general error, I just tried and it works without problems. The error Unknown or bad timezone () means the timezone string is empty. And I do not see how that is possible to happen.

Please create a screenshot of how your exactly create that field. Also show me a screenshot of "Doctor > PHP > date.timezone".

Jelle-S commented 1 year ago

I was debugging it yesterday, and the model_timezone there says null

This is the field config: image

And this is the default timezone: image

From what I can see that option should default to the default timezone. Given that it is null, it must get overridden somewhere? But I can't seem to find where that would be.

kevinpapst commented 1 year ago

Also show me a screenshot of "Doctor > PHP > date.timezone".

And please check what is in date_default_timezone_get()

Once we know how to reproduce it, it should be easy to fix.

Jelle-S commented 1 year ago

That also returns "Europe/Brussels".

Changing https://github.com/kimai/kimai/blob/main/src/Form/Type/TimePickerType.php#L62 to

$now = new \DateTime('now', new \DateTimeZone($options['model_timezone'] ?? date_default_timezone_get()));

seems to fix it, but I don't think that is the right way to fix this, as there seems to be an underlying issue.

Jelle-S commented 1 year ago

After some more debugging, I found that the culprint is https://github.com/kimai/kimai/blob/main/src/Form/Type/DateTimePickerType.php#L116-L117

When I change those null values to date_default_timezone_get() it is fixed... I'm not entirely sure of the inner workings of Symfony/Kimai... So I'm also not sure if that is the right place/way of fixing this issue?

kevinpapst commented 1 year ago

Hahaha, because you said

we get a fatal error on the edit screen of an activity

I thought you get the error when you open the screen... I didn't try actually to save a date-time 🙈 Now I can reproduce it and yes, your proposed fix is correct. I'll add it to the next minor release.

Thanks for debugging 👍

Jelle-S commented 1 year ago

I didn't get it when opening the create screen, correct. I got it on save, but also on editing an existing activity (on the edit screen, before save). Anyway, glad it'll get fixed! Thanks!