mirror of
https://github.com/doctrine/orm.git
synced 2026-03-23 22:42:18 +01:00
Handling DateTimes-Cookbook is … error-prone regarding Timezones #5664
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @heiglandreas on GitHub (Sep 1, 2017).
The DateTime-Cookbook favours to store all DateTimes by converting them to UTC and store them in the Database in UTC. That is a possible approach, but it can (and will) lead to problems as soon as the olson-DB changes. That will lead to differing offsets resulting in wrong DateTimes when hydrating them from the database.
I have not yet found a good solution using the ORM (that's why there isn't a PR by now) but I think it is unwise to give advice that can lead to errors without stating that.
For more information on the topic feel free to have a look at a blogpost I wrote
@Ocramius commented on GitHub (Sep 1, 2017):
Can you suggest a storage format to be used?
On 1 Sep 2017 15:08, "Andreas Heigl" notifications@github.com wrote:
@heiglandreas commented on GitHub (Sep 1, 2017):
Best storage-format IMHO would be local datetime and timezone in 2 separate fields. Important IMHO is that the datetime is not converted to UTC but left in local time. But that would require 2 DB-fields for one PHP-Object. dehydration would be like this:
and hydration on the other side would be like this:
That would also allow users to use in-DB timezone handling as I explained in these articles for Postgres and MySQL
Currently I have no clue as to how one could bring that into Doctrine. I'm happy for all pointers on where to start or how to achieve that…