You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This PQ will make sure that the dates saved in the database (without indication of timezone) is always stored in the UTC timezone.
I was doing development on my machine in Sweden when I noticed that when I created a DateTime, stored it in the db and then retrieved it again, the time was off by two hours. This is because a created the DateTime object with the UTC timezone. Doctrine then saved it straight to the database (by using $date->format(...)) and thus the information about which timezone it was in was lost. When doctrine then fetched the value, it used DateTime::createFromFormat(...) to create a DateTime for me. The problem is that since the timezone wasn't saved anywhere, it assumed that it was a Swedish date, and thus it removed two hours.
I believe that the correct way of doing it is to store the dates in the db as UTC. Then it will always work no matter what the default timezone is, even if I later decide to change it.
date*default_timezone*set('UTC') is not the answer. If I use it, I need to make sure that every DateTime that I pass to doctrine always has the timezone set to UTC. Since the DateTime can come from any number of sources (e.g. third party library) it could easily introduce hard to detect bugs. It will also output every date in the UTC timezone which may not be what I want if I'm developing a localised site (e.g. small page for a local Swedish business).
The text was updated successfully, but these errors were encountered:
Jira issue originally created by user @doctrinebot:
This issue is created automatically through a Github pull request on behalf of LinusU:
Url: #616
Message:
This PQ will make sure that the dates saved in the database (without indication of timezone) is always stored in the UTC timezone.
I was doing development on my machine in Sweden when I noticed that when I created a
DateTime
, stored it in the db and then retrieved it again, the time was off by two hours. This is because a created theDateTime
object with the UTC timezone. Doctrine then saved it straight to the database (by using$date->format(...)
) and thus the information about which timezone it was in was lost. When doctrine then fetched the value, it usedDateTime::createFromFormat(...)
to create aDateTime
for me. The problem is that since the timezone wasn't saved anywhere, it assumed that it was a Swedish date, and thus it removed two hours.I believe that the correct way of doing it is to store the dates in the db as UTC. Then it will always work no matter what the default timezone is, even if I later decide to change it.
date*default_timezone*set('UTC')
is not the answer. If I use it, I need to make sure that everyDateTime
that I pass to doctrine always has the timezone set toUTC
. Since theDateTime
can come from any number of sources (e.g. third party library) it could easily introduce hard to detect bugs. It will also output every date in the UTC timezone which may not be what I want if I'm developing a localised site (e.g. small page for a local Swedish business).The text was updated successfully, but these errors were encountered: