nextcloud / deck

🗂 Kanban-style project & personal management tool for Nextcloud, similar to Trello
https://apps.nextcloud.com/apps/deck
GNU Affero General Public License v3.0
1.22k stars 278 forks source link

DueDate reported with wrong timezone in frontend API #4764

Open pbek opened 1 year ago

pbek commented 1 year ago

I don't know if this is exactly the rather old issue #2276... But I still have the same problem on Nextcloud 26.0.2 (docker) with TZ=Europe/Vienna.

I'm working on a feature for creating Deck Cards in QOwnNotes (https://github.com/pbek/QOwnNotes/issues/2789).

When I use the Deck API to create a Card, I send:

{"duedate":"2023-06-06T06:15:30+02:00","order":0,"title":"tz4","type":"plain"}

I get back:

{"ETag":"8ef788d31fae586d508563b5b52c5de1","archived":false,"assignedUsers":null,"attachmentCount":null,"attachments":null,"commentsCount":0,"commentsUnread":0,"createdAt":1686024933,"deletedAt":0,"description":"","descriptionPrev":null,"duedate":"2023-06-06T06:15:30+02:00","id":78,"labels":null,"lastEditor":null,"lastModified":1686024933,"notified":false,"order":0,"owner":"test","relatedBoard":null,"relatedStack":null,"stackId":16,"title":"tz4","type":"plain"}

Note that the timezones are both correct, 2023-06-06T06:15:30+02:00.

But when I look at the Deck page on my Nextcloud server, the timezone is not correct at all!

2023-06-06T06:15:30+00:00

image

I can't see any useful Nextcloud Log errors/warning in that period.

pbek commented 1 year ago

Timezone looks correct in mariadb too...

image

pbek commented 1 year ago

No, the timezone in the DB is not correct, the MySQL dump showed me '2023-06-06 06:15:30', no TZ, so it's stored without TZ (= UTC).

pbek commented 1 year ago

When I create an entry in the Web UI with 20:00 it's stored correctly as '2023-06-06 18:00:00' in the DB. So Deck seems to store DateTimes without converting it first to UTC via the public API.

pbek commented 1 year ago

I don't know if it's the same issue, but for example here I had to convert new \DateTimeImmutable('now', new DateTimeZone('UTC') to force the conversion.

Here I even had to force date_default_timezone_set('UTC'); to get the API to output UTC.

pbek commented 1 year ago

I found https://github.com/nextcloud/deck/blob/8038e568a3a8ecec29fa8747a2981426d62f3b3d/lib/Service/CardService.php#L238, but I guess at that time there are still strings...

Maybe dealing with it in https://github.com/nextcloud/deck/blob/8038e568a3a8ecec29fa8747a2981426d62f3b3d/lib/Db/CardMapper.php#L77, but I'm fishing in the dark, since Nextcloud seems to handle those conversion.

Fufs commented 10 months ago

Hi, I stumbled on this issue, while looking for a solution for a different one. I think the problem here is that $duedate is passed directly when creating a new card. This is bad because the MySQL datetime type is not timezone aware, as per this doc.

I think someone has encountered this problem before, because if you scroll a bit down, you can see this issue is patched for the update function

https://github.com/nextcloud/deck/blob/bfe2a9053f4d54d5c6b64f6822fabf5143a555ac/lib/Service/CardService.php#L340C1-L340C64

The solution then is to change the create function from

$card->setDuedate($duedate); 

to

$card->setDuedate($duedate ? new \DateTime($duedate) : null);

Hope that helps!