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

Fix Scheduled Reports sent one hour late in daylight saving timezones #10443

Merged
merged 4 commits into from Sep 20, 2016

Conversation

sgiehl
Copy link
Member

@sgiehl sgiehl commented Aug 25, 2016

[Replaces #10318]

This PR aims to fix the issue, that scheduled reports might be sent one hour to late / to early if the reports are saved for an site having a timezone using daylight savings.

The problem occurs because the "hour" the report should be sent at is currently saved in the timezone of the site. That means a new report with the timezone like e.g. Europe/Berlin with the setting to send the report at 8 o'clock would be one hour earlier/later when the daylight saving changes.

Internal Piwik uses UTC for running the tasks, so it tries to adjust the saved hour using the site's timezone difference. At the moment that would be two hours for Europe/Berlin, so the report would sent at 6 o'clock UTC. When the daylight saving changes again, the timezone difference will be only an hour. So Piwik will then reduce the saved hour value only by one to get the UTC time, which will be 7 o'clock (which is one hour later).

To avoid this in the future, I changed the current behavior to not save the hour value in the site's timezone anymore, but to use the UTC time instead. Doing this, the value can't be affected by daylight saving anymore. I also added an update script to update existing reports to have UTC values.

When creating/editing an report for an site using a timezone with a difference to UTC, Piwik will now should the UTC, aswell:

image

fixes #7658, refs #5873

@sgiehl sgiehl added not-in-changelog For issues or pull requests that should not be included in our release changelog on matomo.org. Needs Review PRs that need a code review labels Aug 25, 2016
@sgiehl sgiehl added this to the 2.16.3 milestone Aug 25, 2016
@sgiehl sgiehl self-assigned this Aug 25, 2016
$dateTimeZone = new \DateTimeZone($siteTimezone);

$view->timeZoneDifference = -$dateTimeZone->getOffset(new \DateTime());
$view->countWebsites = count(APISitesManager::getInstance()->getSitesIdWithAtLeastViewAccess());

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't this cause a memory hog, if there are lots of sites added?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If so that would have been there before, as well. I've only added the detection for timezone offset.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I see.

@mkrakiewicz
Copy link

I think it looks OK in general 👍

@sgiehl sgiehl force-pushed the 7658_scheduled_reports branch 3 times, most recently from 603505e to 7c6e8c4 Compare August 26, 2016 17:51
@sgiehl
Copy link
Member Author

sgiehl commented Aug 26, 2016

@mkrakiewicz I've updated the code according to your feedback.
Guess it should be ready to merge then

@sgiehl sgiehl removed their assignment Aug 26, 2016
@mattab
Copy link
Member

mattab commented Aug 30, 2016

@sgiehl

We got a similar report:

[...] Piwik seems to have some weird ideas
about scheduling (I just scheduled a report for Daily at 17:00 for website in UTC+12 timezone, and it
has been scheduled for first run tomorrow at 16:00, and it knows
that's in 1day + some minutes).

Do you think this PR will fix such issue as well, that a report scheduled for 5pm later today in UTC+12 will run today and not tomorrow (in UTC+12 timezone) ?

@sgiehl
Copy link
Member Author

sgiehl commented Aug 30, 2016

Yes, that should fix all time issues regarding scheduled reports. The report hour will always be saved in UTC. And as the scheduling is also done in UTC, the time should always be correct then.

@sgiehl
Copy link
Member Author

sgiehl commented Aug 30, 2016

I'll update the PR later, so it will get mergable again.

@sgiehl sgiehl force-pushed the 7658_scheduled_reports branch 2 times, most recently from e52f560 to 8b5d83c Compare August 30, 2016 16:40
@tsteur tsteur changed the base branch from master to 2.x-dev September 1, 2016 06:36
@@ -122,10 +131,12 @@ function initManagePdf() {

apiParameters.parameters = getReportParametersFunctions[apiParameters.reportType]();

var hour = adjustHourToTimezone($('#report_hour').val());
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please provide -timeZoneDifference as a second argument for adjustHourToTimezone().

Copy link
Member

@mattab mattab Sep 19, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sgiehl as @adaqus pointed out, isn't the second argument missing? if it's 0 then let's write it to make it a bit more clear...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@sgiehl sgiehl removed their assignment Sep 19, 2016
@mattab mattab merged commit 9515909 into 2.x-dev Sep 20, 2016
@mattab mattab deleted the 7658_scheduled_reports branch September 20, 2016 03:26
mattab added a commit that referenced this pull request Sep 26, 2016
* Fix Scheduled Reports sent one hour late in daylight saving timezones (#10443)

* convert hour to send report to/from UTC, to ensure it isn't affected by daylight savings

* adds update script to change existing scheduled reports to use utc time

* code improvement

* adds missing param

* Added new event Archiving.makeNewArchiverObject to  allow customising plugin archiving  (#10366)

* added hook to alllow plugin archiving prevention

* cr code style notes

* reworked PR to fit CR suggestions

* added PHPDoc for hook

* Event description more consistent

* UI tests: minor changes

* Adds test checking if all screenshots are stored in lfs

* removed screenshots not stored in lfs

* readds screenshots to lfs

* 2.16.3-b4
mattab added a commit that referenced this pull request Sep 29, 2016
* Fix depraction test: use assertDeprecatedMethodIsRemovedInPiwik3

* Fix Scheduled Reports sent one hour late in daylight saving timezones (#10443)

* convert hour to send report to/from UTC, to ensure it isn't affected by daylight savings

* adds update script to change existing scheduled reports to use utc time

* code improvement

* adds missing param

* Added new event Archiving.makeNewArchiverObject to  allow customising plugin archiving  (#10366)

* added hook to alllow plugin archiving prevention

* cr code style notes

* reworked PR to fit CR suggestions

* added PHPDoc for hook

* Event description more consistent

* UI tests: minor changes

* Comment out Visitor Log UI tests refs #10536

* Adds test checking if all screenshots are stored in lfs

* removed screenshots not stored in lfs

* readds screenshots to lfs

* 2.16.3-b4

* Issue translation updates against 2.x-dev

* language update

* Fix bug in widget list remove where the JSON object becomes array

* 2.16.3-rc1

* console command custom-piwik-js:update should work when directory is writable and file does not exist yet (#10576)

* followup #10449

* Fix test
(cherry picked from commit fac3d63)

* Prevent chmod(): No such file or directory

* Automatically update all marketplace plugins when updating Piwik (#10527)

* update plugins and piwik at the same time

* make sure plugins are updated with piwik

* use only one try/catch

* reload plugin information once it has been installed

* make sure to clear caches after an update

* fix ui tests

* make sure to use correct php version without any extras

* Additional informations passed in the hook "isExcludedVisit" (issue #10415) (#10564)

* Additional informations passed in the hook "isExcludedVisit" (issue #10415)

* Added better description to the new parameters

* Update VisitExcluded.php

* Remove two parameters not needed as better to use the Request object

* Update VisitExcluded.php

* remove extra two parameters in VisitExcluded constructor to prevent confusion (#10593)

* Update our libs to latest #10526

* Update composer libraries to latest #10526

* Update log analytics to latest

* When updating the config file failed (or when any other file is not writable...), the Updater (for core or plugins) will now automatically throw an error and cancel the update (#10423)

* When updating the config file failed (or when any other file is not writable...), the Updater (for core or plugins) will now automatically throw an error and cancel the update

* add integration test to check the correct exception is thrown when config not writabel

* New integration test for updater

* Make test better

* When opening the visitor profile, do not apply the segment (#10533)

* When opening the visitor profile, do not apply the segment

* added ui test for profile but does work for me

* next try to make ui test work

* add expected screenshot

* added missing doc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs Review PRs that need a code review not-in-changelog For issues or pull requests that should not be included in our release changelog on matomo.org.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants