Why are Laravel timestamps saved using current timezone?

Posted 3 years ago by RoboRobok

When you save a model with Laravel Eloquent, the timestamps are being saved respecting the timezone. For example, let's say you have your app's timezone set to UTC and save a model. It will be this:

+----+----------------------------------+---------------------+---------------------+
| id |               name               |     created_at      |     updated_at      |
+----+----------------------------------+---------------------+---------------------+
|  1 | My model saved with UTC timezone | 2016-06-27 23:15:17 | 2016-06-27 23:15:17 |
+----+----------------------------------+---------------------+---------------------+

They, you change app's timezone to GMT and create new model. Now we have this:

+----+----------------------------------+---------------------+---------------------+
| id |               name               |     created_at      |     updated_at      |
+----+----------------------------------+---------------------+---------------------+
|  1 | My model saved with UTC timezone | 2016-06-27 23:15:17 | 2016-06-27 23:15:17 |
|  2 | My model saved with GMT timezone | 2016-06-27 18:15:17 | 2016-06-27 18:15:17 |
+----+----------------------------------+---------------------+---------------------+

And my question is: is there a reason why Laravel saves timestamps according to app.timezone setting? Wouldn't it be better if Laravel used GMT (or any other) internally and translated it to the desired timestamp afterwards? Currently, changing app timezone will make all timestamps irrelevant.

Am I missing something?

Please sign in or create an account to participate in this conversation.