Skip to content

Bug/12102 timezone fix#12303

Merged
tofumatt merged 22 commits intodevelopfrom
bug/12102-timezone-fix
Mar 18, 2026
Merged

Bug/12102 timezone fix#12303
tofumatt merged 22 commits intodevelopfrom
bug/12102-timezone-fix

Conversation

@zutigrm
Copy link
Collaborator

@zutigrm zutigrm commented Mar 11, 2026

Summary

Addresses issue:

Relevant technical choices

PR Author Checklist

  • My code is tested and passes existing unit tests.
  • My code has an appropriate set of unit tests which all pass.
  • My code is backward-compatible with WordPress 5.2 and PHP 7.4.
  • My code follows the WordPress coding standards.
  • My code has proper inline documentation.
  • I have added a QA Brief on the issue linked above.
  • I have signed the Contributor License Agreement (see https://cla.developers.google.com/).

Do not alter or remove anything below. The following sections will be managed by moderators only.

Code Reviewer Checklist

  • Run the code.
  • Ensure the acceptance criteria are satisfied.
  • Reassess the implementation with the IB.
  • Ensure no unrelated changes are included.
  • Ensure CI checks pass.
  • Check Storybook where applicable.
  • Ensure there is a QA Brief.
  • Ensure there are no unexpected significant changes to file sizes.

Merge Reviewer Checklist

  • Ensure the PR has the correct target branch.
  • Double-check that the PR is okay to be merged.
  • Ensure the corresponding issue has a ZenHub release assigned.
  • Add a changelog message to the issue.

@github-actions
Copy link

github-actions bot commented Mar 11, 2026

Build files for a889481 are ready:

Copy link
Collaborator

@benbowler benbowler left a comment

Choose a reason for hiding this comment

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

A few inline comments.

After doing this I noticed that the plugin is still showing the difference in timings in the tester plugin:

Image

I found a few bugs in date/timezone shifting in the tester plugin, so I've fixed it, as well as updated it to pass the timestamp, and will share it in Slack for testing.

self::factory()->user->create(),
);

$scheduled_timestamp = 1_700_010_000;
Copy link
Collaborator

Choose a reason for hiding this comment

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

It's worth adding a comment for readability here or using strtotime to make this readable.

}

public function test_handle_callback_action_without_subscribers_still_schedules_follow_up_events() {
$scheduled_timestamp = 1_700_020_000;
Copy link
Collaborator

Choose a reason for hiding this comment

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

As above.

return;
}

$next = $this->frequency_planner->next_occurrence( $frequency, time(), wp_timezone() );
Copy link
Collaborator

Choose a reason for hiding this comment

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

This code is adding wp_timezone calls, which are not compatible with WP 5.2. Can this be updated here to us BC_Functions so that it doesn't need to be captured in #12311

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That's a good point, it will be faster to include it here

@@ -93,7 +93,59 @@ public function schedule_initiator_once( $frequency ) {
public function schedule_next_initiator( $frequency, $timestamp ) {
$next = $this->frequency_planner->next_occurrence( $frequency, $timestamp, wp_timezone() );
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same here.

Copy link
Collaborator

@benbowler benbowler left a comment

Choose a reason for hiding this comment

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

✅ CR

@github-actions
Copy link

github-actions bot commented Mar 17, 2026

🤖 This comment is automatically updated by CI workflows. Each section is managed independently.

📦 Build files for 50da565:

🎭 Playwright reports for 50da565:

Copy link
Collaborator

@benbowler benbowler left a comment

Choose a reason for hiding this comment

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

Thanks @zutigrm, I addressed two missed uses within tests for consistency, even though tests are likely to run above PHP 5.2.

✅ CR

Copy link
Collaborator

@tofumatt tofumatt left a comment

Choose a reason for hiding this comment

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

This looks good, but I have concerns about the private API usage 😅

* @return int|false Timestamp if found, otherwise false.
*/
public function get_initiator_timestamp( $frequency ) {
$cron = _get_cron_array();
Copy link
Collaborator

Choose a reason for hiding this comment

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

🤔 This is a private function (clearly marked as such with the leading underscore) and is explicitly marked as not being for third-parties to use/rely on: https://developer.wordpress.org/reference/functions/_get_cron_array/

Using private functions like this could cause Site Kit to break unexpectedly in the future—I know we test nightly versions of WordPress right now to check on this sort of thing, but is there any way we can get this data without relying on a private API?

I'd really rather us not use APIs like this, and it wasn't mentioned in the IB.


If we do need to use this, at the absolute minimum, we should thoroughly document our reasoning for using this private API (why public APIs can't provide the data we need).

I can see we have tests for this function so that's good 😄.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We are using it here because of dynamic timestamp argument, so default wp_next_scheduled check won;t do as we don't have static arguments for hook to be correctly identified. The reasoning is explained in detail already in the method header doc:

/**
* Gets the timestamp of the next initiator event for a frequency.
*
* We intentionally scan cron entries instead of using wp_next_scheduled()
* because initiators are scheduled with dynamic args:
* [ $frequency, $scheduled_timestamp ]. wp_next_scheduled() requires an
* exact args match, but here we only need to know whether any initiator
* exists for a given frequency regardless of its scheduled timestamp.
*
* @SInCE n.e.x.t
*
* @param string $frequency Frequency slug.
* @return int|false Timestamp if found, otherwise false.
*/

Similar reason we also use this internal check on uninstallation hook:

private function is_event_scheduled( $hook ) {
$crons = _get_cron_array();
if ( ! is_array( $crons ) || empty( $crons ) ) {
return false;
}
foreach ( $crons as $events ) {
if ( isset( $events[ $hook ] ) ) {
return true;
}
}
return false;

Copy link
Collaborator

@tofumatt tofumatt left a comment

Choose a reason for hiding this comment

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

Cool, makes sense, thanks! 👍🏻

@tofumatt tofumatt merged commit 3821979 into develop Mar 18, 2026
18 of 20 checks passed
@tofumatt tofumatt deleted the bug/12102-timezone-fix branch March 18, 2026 18:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants