-
Notifications
You must be signed in to change notification settings - Fork 339
Email Report Scheduler time does not account for timezone #12102
Copy link
Copy link
Closed
Labels
P2Low priorityLow priorityTeam SIssues for Squad 1Issues for Squad 1Type: BugSomething isn't workingSomething isn't working
Description
Bug Description
@aaemnnosttv noticed that the timestamp for him appears to be GMT or similar for all workers:
Also the quarterly worker is one hour later than the others.
These should be scheduled based on the default timezone of the account.
Do not alter or remove anything below. The following sections will be managed by moderators only.
Acceptance criteria
- Every scheduler should be scheduled for midnight on the day of the end of the relevant period, in the default timezone of the site.
Implementation Brief
The drift seems to happen because the batch timestamp is currently set with
time()at execution, so if WP‑Cron fires late, workers, fallbacks, and reference dates are anchored to the execution time, not the scheduled midnight in the site timezone.
- Schedule initiator with the computed timestamp
Email_Reporting_Scheduler.php- In
schedule_initiator_once()andschedule_next_initiator(), schedule the initiator with args[ $frequency, $next_timestamp ](instead of only$frequency).
- In
- Accept the timestamp in the initiator callback
Email_Reporting.php:- Update the initiator hook to accept 2 args (
add_action( Email_Reporting_Scheduler::ACTION_INITIATOR, ...., 10, 2)
- Update the initiator hook to accept 2 args (
- In
Initiator_Task.php:handle_callback_actionmethod should use$scheduled_timestampinstead of currenttime()- Use this timestamp for:
schedule_worker( …, $scheduled_timestamp )schedule_fallback( …, $scheduled_timestamp )build_reference_dates( …, $scheduled_timestamp )
Test Coverage
Email_Reporting_SchedulerTest.php- Update assertions to include the new args
[ $frequency, $expected_timestamp ].
- Update assertions to include the new args
Initiator_TaskTest.php- Add a test to assert that when
handle_callback_actionis called, the worker and fallback schedules receive the same$scheduled_timestamp
- Add a test to assert that when
Frequency_PlannerTest.php- Use a fixed UTC timestamp and compute
next_occurrencefor UTC vsAmerica/Los_Angelesfor example. - Assert the timestamps are not equal and each resolves to midnight in the respective timezone.
- Use a fixed UTC timestamp and compute
QA Brief
It was historically a bit difficult to reproduce this issue. You can try to QA this issue using these steps:
- Set site timezone in Settings > General to a non-UTC zone (e.g. America/Los_Angeles).
- Enable email reporting and subscribe to a frequency, eq
weekly. - In Tools > Cron Events (WP Crontrol plugin is needed), check
googlesitekit_email_reporting_initiatorevents:- args include
[frequency, scheduled_timestamp] - scheduled time is local midnight for that period boundary.
- args include
- Trigger initiator event for selected frequency (
weeklyif you subscribed to weekly reports) manually (Run Now) and verify new worker/fallback events are created with the same initiator timestamp in args. - Verify email report align with the scheduled day, not the actual run time.
- Switch timezone to UTC, reschedule, and confirm timestamps shift accordingly while still landing on midnight in that timezone. After switching the timezone setting, note that scheduled CRON is still running on initial setting during which it was scheduled. So to force it to reschedule under new timezone, delete the scheduled CRON so it can be recreated under new timezone
Changelog entry
- Fix timezone bugs with scheduled emails.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
P2Low priorityLow priorityTeam SIssues for Squad 1Issues for Squad 1Type: BugSomething isn't workingSomething isn't working