Skip to content

Abilities: Accept a date-time without an offset in the date-time schema format - #86845

Merged
jorgefilipecosta merged 2 commits into
trunkfrom
fix/abilities-date-time-format-optional-offset
Nov 20, 2026
Merged

jorgefilipecosta merged 2 commits into
trunkfrom
fix/abilities-date-time-format-optional-offset

Conversation

@jorgefilipecosta

Copy link
Copy Markdown
Member

What?

Follow up to #79555.

The client-side validator of @wordpress/abilities now accepts a date-time without a time zone offset, such as 2026-10-21T09:30:00, for the date-time schema format. The server already accepts it.

A date-time with an offset is valid as before. A value that is not a full date and time is still rejected.

Why?

The schema of an ability is checked in two places: on the server by rest_validate_value_from_schema(), and in the client by executeAbility(), which validates the input before it sends the request and the result when it arrives. For date-time the two disagree:

  • On the server the format is checked by rest_parse_date(), where the offset is optional. 2026-10-21T09:30:00 is valid.
  • In the client the format is the date-time check of ajv-formats, which follows RFC 3339 and requires the offset. 2026-10-21T09:30:00 gives Invalid date.

A date without an offset is the usual form in WordPress, not an edge case:

  • The REST API returns date, date_gmt, modified and modified_gmt in that form, and declares them with format: date-time.
  • The REST API reads that form too: a date without an offset is the time of the site, and a date_gmt without an offset is UTC (rest_get_date_with_gmt()).

So two kinds of call fail in the client, for values that the server accepts:

  1. Input. An ability that takes a date with format: date-time cannot be called with a date in the time of the site. executeAbility() throws ability_invalid_input and the request is never sent.
  2. Output. An ability that returns a date in the form the REST API returns, for example one that passes on a REST response or uses mysql_to_rfc3339(), passes validation on the server. The client then throws ability_invalid_output. One such value is enough: the caller gets none of the result.

How core abilities use the date-time format

Already in WordPress trunk, in the output:

  • core/content-query: date and modified, each an object with site and gmt.
  • core/users-query: registered, with the same two keys.

These values always have the offset, for example 2026-10-21T09:30:00+01:00, so they pass the strict check. No core ability fails today, and this PR does not change what they return.

Proposed, in the input (WordPress/abilities#22):

  • core/content-create, core/content-update, core/media-upload and core/media-update take data.date, an object with site, gmt or both, each with format: date-time.
  • The value is read as the REST API reads date and date_gmt. With an offset it is that moment. Without an offset, site is the time of the site and gmt is UTC.
  • The form without an offset is how a caller says "publish at 09:00, site time". The caller does not have to know the offset of the site on that day, which changes with daylight saving time.

With the strict check, the client would refuse exactly that call:

await executeAbility( 'core/content-create', {
	data: {
		type: 'post',
		title: 'Beta closes today',
		status: 'future',
		date: { site: '2026-10-23T09:00:00' },
	},
} );
// Error: Ability "core/content-create" has invalid input. Reason: Invalid date.

How?

date-time is no longer in the list of formats given to addFormats(). It is registered with ajv.addFormat( 'date-time', addFormats.get( 'iso-date-time' ) ).

iso-date-time is a format that ajv-formats already has: the date-time check with the time zone made optional. There is no new dependency and no new regular expression.

The error message does not change: Invalid date.

Value Server Client before Client after
2026-10-21T09:30:00+01:00 valid valid valid
2026-10-21T08:30:00Z valid valid valid
2026-10-21T08:30:00.123Z valid valid valid
2026-10-21 09:30:00+01:00 valid valid valid
2026-10-21T09:30:00 valid invalid valid
2026-10-21T09:30:00.123 valid invalid valid
2026-10-21 09:30:00 valid invalid valid
2026-10-21 invalid invalid invalid
2026-10-21T09:30 invalid invalid invalid
2026-13-01T09:30:00 invalid invalid invalid
October 21, 2026 invalid invalid invalid
An empty string invalid invalid invalid

The change is only the three rows in the middle. Two differences between the client and the server remain, as before:

  • The client is stricter about dates that do not exist. 2026-02-30T09:30:00 and 2026-10-21T24:00:00 are invalid in the client; the server rolls them over to the next valid date.
  • The client is more lenient about the offset. 2026-10-21T09:30:00+0100, with no colon, is valid in the client and invalid on the server.

This PR and #86844 change the same call to addFormats() and the same section of the changelog. They are independent, and the second one to merge needs a rebase.

Testing Instructions

  1. Run npm run test:unit -- packages/abilities/src/tests/validation.test.ts. All tests pass.
  2. The new tests are in the AI-relevant format validation group:
    • should accept %s as a date-time: seven forms that the server accepts, with and without an offset.
    • should reject %s as a date-time: an empty string, a date without a time, a time without a date, a time without seconds, a month, a day and an hour that do not exist, and a date in words.
    • should validate the dates in an input shaped like the input of a core ability: data.date with site and gmt, with the error for a date without a time.
    • should validate the dates in a result that has them in the form the REST API returns: date and date_gmt without an offset.
  3. To see the bug, revert the change to packages/abilities/src/validation.ts and run the tests again: five of the new tests fail.

Testing Instructions for Keyboard

Not applicable, there is no change to the user interface.

Screenshots or screencast

Not applicable.

Use of AI Tools

An AI coding assistant drafted the code change, the tests and this description.

@jorgefilipecosta jorgefilipecosta added [Type] Bug An existing feature does not function as intended [Package] Abilities /packages/abilities labels Nov 14, 2026
@github-actions

github-actions Bot commented Nov 14, 2026 •

Copy link
Copy Markdown

🤖 PR meta 🤖

Preview in WordPress Playground Preview in Storybook

🎉 Props

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: jorgefilipecosta <jorgefilipecosta@git.wordpress.org>
Co-authored-by: gziolo <gziolo@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.


Props Bot commands

You can trigger Props Bot actions by commenting on this PR:

  • @propsbot add <username> to give props to a GitHub user. Requires write access.
  • @propsbot remove <username> to leave a user out of the props. Requires write access.
  • @propsbot refresh to refresh this list. Adding the props-bot label works too.

Updated as activity occurs, without notifying anyone named here. Add the props-bot label to refresh.

📦 Bundle size

Size Change: +14 B (0%)

Total Size: 8.69 MB

📦 View Changed
Filename Size Change
build/modules/abilities/index.min.js 41.2 kB +14 B (+0.03%)

9ea77f4 Run

⚡ Performance

Show the results

Client side metrics exclude the server response time.

front-end-block-theme

Metric 06d603e trunk % Change
timeToFirstByte 38.25 ms +8.37% -5.49% 34.65 ms +21.65% -2.02% 10.39%
largestContentfulPaint 68 ms +5.88% -11.76% 60 ms +6.67% -6.67% 13.33%
lcpMinusTtfb 27.8 ms +8.81% -15.11% 22.25 ms +12.13% -3.37% 24.94%
wpBeforeTemplate 19.66 ms +11.65% -3.56% 17.94 ms +20.18% -1.73% 9.59%
wpTemplate 15.02 ms +4.06% -6.86% 13.86 ms +6.78% -4.18% 8.37%
wpTotal 34.96 ms +8.07% -5.41% 31.65 ms +21.23% -2.59% 10.46%
wpMemoryUsage 7.75 MB +0% -0% 7.72 MB +0% -0% 0.45%
wpDbQueries 16 +0% -0% 16 +0% -0% 0%

front-end-classic-theme

Metric 06d603e trunk % Change
timeToFirstByte 31 ms +9.52% -2.58% 29.4 ms +4.25% -2.89% 5.44%
largestContentfulPaint 60 ms +3.33% -6.67% 54 ms +3.7% -3.7% 11.11%
lcpMinusTtfb 27.25 ms +6.79% -5.87% 24.7 ms +5.87% -5.47% 10.32%
wpBeforeTemplate 17.17 ms +11.3% -3.32% 15.99 ms +7.69% -2.25% 7.38%
wpTemplate 11.04 ms +5.71% -4.17% 10.66 ms +2.44% -8.07% 3.56%
wpTotal 28.33 ms +7.62% -3.53% 26.75 ms +4.49% -3.4% 5.91%
wpMemoryUsage 6.44 MB +0% -0% 6.40 MB +0% -0% 0.56%
wpDbQueries 13 +0% -0% 13 +0% -0% 0%

media-processing

Metric 06d603e trunk % Change
mediaProcessingJpeg 229.83 ms +1.92% -1.84% 222.49 ms +3.83% -0.96% 3.3%
mediaProcessingAvif 3683.25 ms +0.54% -0.59% 3654.39 ms +1.21% -0.91% 0.79%
mediaProcessingJpegToAvif 2580.99 ms +1.07% -0.77% 2570.3 ms +0.31% -3.97% 0.42%

media-upload

Metric 06d603e trunk % Change
jpegUploadProcessing 1477.78 ms +1.05% -2.27% 1436.25 ms +2.79% -1.54% 2.89%
pngUploadProcessing 208.79 ms +4.02% -7.36% 195.56 ms +8.31% -4.42% 6.77%
largeJpegUploadProcessing 1463.72 ms +0.93% -1.38% 1449.2 ms +1.5% -0.56% 1%
multipleImageUploadProcessing 1509.04 ms +2.05% -0.81% 1521.08 ms +1.23% -0.76% -0.79%

post-editor

Metric 06d603e trunk % Change
serverResponse 450.36 ms +7.44% -3.73% 465.17 ms +4.45% -5.72% -3.18%
firstPaint 417.3 ms +5.55% -9.5% 411.34 ms +6.39% -4.87% 1.45%
domContentLoaded 814.86 ms +8.85% -0.21% 816.63 ms +1.55% -1.36% -0.22%
loaded 815.87 ms +8.85% -0.19% 817.85 ms +1.53% -1.4% -0.24%
firstContentfulPaint 465.74 ms +10.53% -2.13% 457.48 ms +3.29% -1.7% 1.81%
firstBlock 2186.51 ms +3.33% -1.27% 2160.19 ms +2.02% -1.17% 1.22%
type 17.66 ms +4.81% -15.12% 17.85 ms +9.13% -8.8% -1.06%
typeWithoutInspector 21.13 ms +19.5% -8.19% 16.98 ms +9.66% -6.07% 24.44%
typeWithTopToolbar 24.14 ms +4.97% -6.26% 22.1 ms +8.87% -3.08% 9.23%
typeContainer 8.28 ms +8.45% -7.37% 8.05 ms +10.31% -17.14% 2.86%
focus 123.13 ms +4.03% -10.92% 115.13 ms +3.56% -4.79% 6.95%
firstFocus 255.66 ms +0% -0% 256.32 ms +0% -0% -0.26%
selectAll 424.03 ms +3.68% -0.48% 411.35 ms +0.78% -4.71% 3.08%
undo 27.85 ms +7.07% -3.52% 29.37 ms +4.9% -8% -5.18%
listViewOpen 80.2 ms +9.96% -5.82% 71.33 ms +18.58% -1.68% 12.44%
inserterOpen 38.66 ms +3.85% -9.31% 41.12 ms +9.97% -12.11% -5.98%
inserterHover 11.2 ms +4.02% -12.23% 11.69 ms +3.76% -5.56% -4.19%
inserterSearch 7.97 ms +12.92% -7.65% 8.43 ms +5.34% -4.63% -5.46%
loadPatterns 629.2 ms +2.37% -4.39% 633.73 ms +6.44% -6.43% -0.71%
wpTotal 440.74 ms +7.61% -3.81% 455.53 ms +4.55% -5.85% -3.25%
wpMemoryUsage 14.81 MB +0% -0% 14.77 MB +0% -0% 0.25%
wpDbQueries 55 +0% -0% 55 +0% -0% 0%

site-editor

Metric 06d603e trunk % Change
serverResponse 251 ms +1.06% -2.76% 244.24 ms +4.16% -2.33% 2.77%
firstPaint 288.19 ms +6.84% -16.27% 296.08 ms +3.81% -16.81% -2.66%
domContentLoaded 505.44 ms +7.1% -0.33% 526.45 ms +0.47% -2.76% -3.99%
loaded 506.13 ms +7.11% -0.29% 527.29 ms +0.47% -2.78% -4.01%
firstContentfulPaint 300.13 ms +4.62% -5.59% 306.77 ms +1.65% -1.77% -2.16%
firstBlock 1561.86 ms +11.87% -0.67% 1591.49 ms +1% -1.03% -1.86%
type 11.92 ms +8.64% -5.45% 11.93 ms +0.67% -8.38% -0.08%
navigate 70.07 ms +8.28% -3.95% 66.41 ms +10.36% -1.96% 5.51%
loadPatterns 892.08 ms +4.04% -6.98% 948.64 ms +4.86% -12.08% -5.96%
loadPages 916.27 ms +5.56% -1.7% 945.41 ms +6.08% -1.35% -3.08%
wpTotal 244.78 ms +1.12% -2.79% 237.93 ms +4.35% -2.45% 2.88%
wpMemoryUsage 12.83 MB +0% -0% 12.80 MB +0% -0% 0.25%
wpDbQueries 45 +0% -0% 45 +0% -0% 0%

9ea77f4 Run

🏁 Flaky tests

Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

falls back to the first tab when the default tab is removed in /test/e2e/specs/editor/blocks/tabs.spec.js, passed after 1 failed attempt.
Error: expect(received).toBe(expected) // Object.is equality

Expected: 1
Received: 0

Call Log:
- Timeout 5000ms exceeded while waiting on the predicate
    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/blocks/tabs.spec.js:718:60

9ea77f4 Run

…hema format

The `date-time` check of ajv-formats requires a time zone offset, as RFC 3339 does. WordPress does not: `rest_parse_date()`, which validates the format on the server, accepts `2026-10-21T09:30:00`, and the REST API returns `date` and `date_gmt` in that form.

Register the format with the `iso-date-time` check of ajv-formats, which is the same check with the offset made optional, so that the client accepts the dates that the server accepts.
@jorgefilipecosta
jorgefilipecosta force-pushed the fix/abilities-date-time-format-optional-offset branch from 472f3b2 to 9ea77f4 Compare November 20, 2026 18:04

@gziolo gziolo left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good to me! Thanks for explaining the distinction between dates with an explicit offset and dates in the site's timezone—the description covers why this is needed well.

I explored it further with Codex, and verification confirmed the behavior described, including WordPress handling the different winter and summer offsets. The change accepts these values without altering them, leaving their interpretation to the server.

All checks passed, including testing this together with #86844. Reusing the existing iso-date-time validator makes sense here.

@jorgefilipecosta jorgefilipecosta added the Backport to WP 7.2 Beta/RC Pull request that needs to be backported to the WordPress major release that's currently in beta label Nov 20, 2026
@jorgefilipecosta
jorgefilipecosta merged commit 5f63c28 into trunk Nov 20, 2026
97 checks passed
@jorgefilipecosta
jorgefilipecosta deleted the fix/abilities-date-time-format-optional-offset branch November 20, 2026 18:35
@github-actions github-actions Bot added this to the Gutenberg 24.6 milestone Nov 20, 2026
@github-actions

Copy link
Copy Markdown

There was a conflict while trying to cherry-pick the commit to the wp/7.2 branch. Please resolve the conflict manually and create a PR to the wp/7.2 branch.

PRs to wp/7.2 are similar to PRs to trunk, but you should base your PR on the wp/7.2 branch instead of trunk.

# Checkout the wp/7.2 branch instead of trunk.
git checkout wp/7.2

# Create a new branch for your PR.
git checkout -b my-branch

# Cherry-pick the commit.
git cherry-pick 5f63c28ac82d9261f81b40002b97b118df1ba116

# Check which files have conflicts.
git status

# Resolve the conflict...
# Add the resolved files to the staging area.
git status
git add .
git cherry-pick --continue

# Push the branch to the repository
git push origin my-branch

# Create a PR and set the base to the wp/7.2 branch.
# See https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/changing-the-base-branch-of-a-pull-request.

@peterwilsoncc

Copy link
Copy Markdown
Contributor

Manual backport to wp/7.2: #87311

peterwilsoncc pushed a commit that referenced this pull request Nov 24, 2026
…hema format (#86845)

The changelog entry goes in a new `Bug Fixes` section under `Unreleased`, because `wp/7.2` does not have trunk's `0.25.0` and `0.26.0` release sections.

(cherry picked from commit 5f63c28)

Co-authored-by: jorgefilipecosta <jorgefilipecosta@git.wordpress.org>
Co-authored-by: gziolo <gziolo@git.wordpress.org>
peterwilsoncc added a commit that referenced this pull request Nov 24, 2026
…hema format (#86845) (#87311)

The changelog entry goes in a new `Bug Fixes` section under `Unreleased`, because `wp/7.2` does not have trunk's `0.25.0` and `0.26.0` release sections.

(cherry picked from commit 5f63c28)

Co-authored-by: Jorge Costa <jorge.costa@automattic.com>
Co-authored-by: jorgefilipecosta <jorgefilipecosta@git.wordpress.org>
Co-authored-by: gziolo <gziolo@git.wordpress.org>
@Mamaduka Mamaduka added Backported to WP Core Pull request that has been successfully merged into WP Core and removed Backport to WP 7.2 Beta/RC Pull request that needs to be backported to the WordPress major release that's currently in beta labels Nov 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Backported to WP Core Pull request that has been successfully merged into WP Core [Package] Abilities /packages/abilities [Type] Bug An existing feature does not function as intended

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants