mirror of
https://github.com/doctrine/orm.git
synced 2026-03-24 06:52:09 +01:00
Timezone handling for DateTime arguments for queries #5976
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 @stof on GitHub (May 30, 2018).
Feature Request
Summary
Currently, the type of a parameter with a DateTimeInterface value gets guessed as being
datetime. In case the DB field is a datetimetz and the default timezone of the server does not match the timezone of your DateTime object, this might create some issues.My proposal is to change the guessing to use the full precision of the value, by guessing it as
datetimetz.Here is my evaluation of the impact:
datetimetz(MySQL for instance), as DBAL silently treats it asdatetimeinternally anyway (and so the behavior would be the same than today)datetimefield in their mapping on a platform supportingdatetimetz, because the argument passed to the DB would now use the timezone of the argument (and convert it to the DB timezone) instead of assuming that the argument was already in the timezone of the DB. If your PHP server and your DB server already use the same default timezone, you are safe (unless you create objects in a non-default timezone and pass them directly to the DB without converting them, and expecting that no timezone conversion happens). If you have different default timezones, weird things might happen (as Doctrine creates the DateTime objects in the default PHP timezone when reading the datetime field as it does not know the DB timezone)datetimetzfield on a platform supporting them: timezones are now handled properly.I think this is important, as all best practices I saw in the postgresql ecosystem were saying "store the timestamp with timezone", precisely to avoid issues where the DB server and the application server have to agree on the timezone otherwise.
If we want to reduce the impact for people using
datetime, we could imagine having a configuration setting to choose what the default datetime handling should be (datetimetzordatetime) depending on their project needs.@goetas commented on GitHub (May 6, 2019):
PostgreSQL officially discourages the use of timestamp without time zone when storing timestamps (the PHP Datetime object). See https://wiki.postgresql.org/wiki/Don't_Do_This#Don.27t_use_timestamp_.28without_time_zone.29 that gives some very good reasons for it.
So if is for 3.0 I'm totally for this change!
@itinance commented on GitHub (Nov 10, 2023):
any news on this?