Skip to content

Commit c7f71a1

Browse files
author
Enej Bajgoric
committed
Sitemaps abilities: format next_scheduled_at as ISO 8601 UTC (Z suffix) for unambiguous timezone
1 parent f840404 commit c7f71a1

2 files changed

Lines changed: 13 additions & 10 deletions

File tree

projects/plugins/jetpack/modules/sitemaps/abilities/class-sitemaps-abilities.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ public static function get_abilities(): array {
126126

127127
'jetpack-sitemaps/request-rebuild' => array(
128128
'label' => __( 'Request a Jetpack Sitemaps rebuild', 'jetpack' ),
129-
'description' => __( 'Dispatch a full sitemap regeneration by scheduling the existing `jp_sitemap_cron_hook` cron event. Returns { dispatched, status, next_scheduled_at } where status is one of "queued" (a single-event cron tick was just scheduled), "running" (a build is already in flight per the `jetpack-sitemap-state-lock` transient), or "already_running" (alias of "running"; surfaced so callers can branch on either spelling). `next_scheduled_at` is the next `jp_sitemap_cron_hook` tick as a "YYYY-MM-DD HH:mm:ss" UTC string, or null when nothing is scheduled (e.g. status=running with no future tick queued) — it tells the caller when the build they queued (or the one already pending) will actually run. Idempotent — calling this while a build is already in flight or already queued returns dispatched=false and the matching status rather than stacking duplicate cron events.', 'jetpack' ),
129+
'description' => __( 'Dispatch a full sitemap regeneration by scheduling the existing `jp_sitemap_cron_hook` cron event. Returns { dispatched, status, next_scheduled_at } where status is one of "queued" (a single-event cron tick was just scheduled), "running" (a build is already in flight per the `jetpack-sitemap-state-lock` transient), or "already_running" (alias of "running"; surfaced so callers can branch on either spelling). `next_scheduled_at` is the next `jp_sitemap_cron_hook` tick as an ISO 8601 UTC string with an explicit `Z` zone designator (e.g. `2026-05-19T19:33:20Z`), or null when nothing is scheduled (e.g. status=running with no future tick queued) — it tells the caller when the build they queued (or the one already pending) will actually run. Idempotent — calling this while a build is already in flight or already queued returns dispatched=false and the matching status rather than stacking duplicate cron events.', 'jetpack' ),
130130
'input_schema' => array(
131131
'type' => 'object',
132132
'additionalProperties' => false,
@@ -423,22 +423,25 @@ protected static function schedule_rebuild(): void {
423423
}
424424

425425
/**
426-
* When the next `jp_sitemap_cron_hook` build tick is scheduled, as a UTC
427-
* "Y-m-d H:i:s" string, or null when nothing is scheduled.
426+
* When the next `jp_sitemap_cron_hook` build tick is scheduled, as an
427+
* ISO 8601 UTC string (e.g. `2026-05-19T19:33:20Z`), or null when nothing
428+
* is scheduled.
428429
*
429430
* Returned alongside the dispatch result so callers immediately know when
430431
* the build they queued (or the one already pending) will actually run,
431432
* without a second round-trip. Null in the `running` case when the lock is
432433
* held but no future tick is queued.
433434
*
434-
* UTC string (not `human_time_diff()`) for an unambiguous, locale-stable,
435-
* machine-parseable value consistent with the rest of the sitemaps surface.
435+
* ISO 8601 with the explicit `Z` zone designator (not `human_time_diff()`,
436+
* not a bare "Y-m-d H:i:s") so the timezone is unambiguous and the value is
437+
* locale-stable and machine-parseable — the same format the `sitemaps[]`
438+
* `lastmod` values use in `get-status`.
436439
*/
437440
protected static function get_next_scheduled_at(): ?string {
438441
$timestamp = wp_next_scheduled( self::CRON_HOOK );
439442
if ( false === $timestamp ) {
440443
return null;
441444
}
442-
return gmdate( 'Y-m-d H:i:s', $timestamp );
445+
return gmdate( 'Y-m-d\TH:i:s\Z', $timestamp );
443446
}
444447
}

projects/plugins/jetpack/tests/php/src/Sitemaps_Abilities_Test.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -575,8 +575,8 @@ public function test_request_rebuild_returns_queued_when_cron_already_scheduled(
575575
// The previously-scheduled tick should still be the next one (i.e. we
576576
// didn't stack a new one at time() that would overshadow it).
577577
$this->assertSame( $future, wp_next_scheduled( 'jp_sitemap_cron_hook' ) );
578-
// next_scheduled_at reflects that pending tick as a UTC string.
579-
$this->assertSame( gmdate( 'Y-m-d H:i:s', $future ), $result['next_scheduled_at'] );
578+
// next_scheduled_at reflects that pending tick as an ISO 8601 UTC string.
579+
$this->assertSame( gmdate( 'Y-m-d\TH:i:s\Z', $future ), $result['next_scheduled_at'] );
580580
}
581581

582582
/**
@@ -598,8 +598,8 @@ public function test_request_rebuild_dispatches_when_nothing_running_or_queued()
598598
$scheduled,
599599
'A cron event should be scheduled after a successful dispatch.'
600600
);
601-
// The freshly-scheduled tick is reported as a UTC string.
602-
$this->assertSame( gmdate( 'Y-m-d H:i:s', $scheduled ), $result['next_scheduled_at'] );
601+
// The freshly-scheduled tick is reported as an ISO 8601 UTC string.
602+
$this->assertSame( gmdate( 'Y-m-d\TH:i:s\Z', $scheduled ), $result['next_scheduled_at'] );
603603
}
604604

605605
/**

0 commit comments

Comments
 (0)