-
-
Notifications
You must be signed in to change notification settings - Fork 391
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Always store executed_at in UTC and render using date_default_timezone() #706
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This really needs a test.
Consider testing different timezones using date_default_timezone_[gs]et()
(and restore it to previous state at the end of a test).
lib/Doctrine/Migrations/Version.php
Outdated
@@ -221,7 +226,7 @@ private function getWriteSqlFileMigratorConfig() : MigratorConfig | |||
private function getExecutedAtDatabaseValue() : string | |||
{ | |||
return Type::getType(MigrationTable::MIGRATION_EXECUTED_AT_COLUMN_TYPE)->convertToDatabaseValue( | |||
new DateTimeImmutable(), | |||
(new DateTimeImmutable('now', new DateTimeZone(date_default_timezone_get())))->setTimezone(new DateTimeZone('UTC')), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can drop new DateTimeZone(date_default_timezone_get()))
, it's default behavior.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 Just two details below.
{ | ||
$originalTimeZone = date_default_timezone_get(); | ||
|
||
date_default_timezone_set($timeZone); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd put whole test after this statement inside try { ... }
and then date_default_timezone_set($originalTimeZone);
inside finally
, otherwise when the test fails, the timezone will stay messed up.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FIWI, there's TestCase::iniSet()
which could be use to simplify the cleanup. Also, it will throw an explicit exception in the case of a failure and fail the test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool, didn't know it exists. 👍
{ | ||
return [ | ||
['America/New_York'], | ||
['Indian/Chagos'], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would maybe also add 'UTC'
? :)
Summary
Always store executed_at in UTC and render using date_default_timezone()