Skip to content
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

Merged
merged 1 commit into from
May 30, 2018

Conversation

jwage
Copy link
Member

@jwage jwage commented May 30, 2018

Q A
Type enhancement
BC Break no
Fixed issues #702

Summary

Always store executed_at in UTC and render using date_default_timezone()

@jwage jwage added this to the 2.0 milestone May 30, 2018
@jwage jwage self-assigned this May 30, 2018
@jwage jwage force-pushed the executed-at-utc branch from 46cd6ad to 5fcfe82 Compare May 30, 2018 17:56
@jwage jwage requested a review from Majkl578 May 30, 2018 17:58
Copy link
Contributor

@Majkl578 Majkl578 left a 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).

@@ -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')),
Copy link
Contributor

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.

@jwage jwage force-pushed the executed-at-utc branch from 5fcfe82 to ab1359e Compare May 30, 2018 20:29
@jwage jwage requested a review from Majkl578 May 30, 2018 20:30
Copy link
Contributor

@Majkl578 Majkl578 left a 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);
Copy link
Contributor

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.

Copy link
Member

@morozov morozov May 30, 2018

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.

Copy link
Contributor

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'],
Copy link
Contributor

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'? :)

@jwage jwage force-pushed the executed-at-utc branch from ab1359e to 5b58184 Compare May 30, 2018 23:19
@jwage jwage requested a review from Majkl578 May 30, 2018 23:20
@jwage jwage merged commit c243529 into master May 30, 2018
@jwage jwage deleted the executed-at-utc branch May 30, 2018 23:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants