Repository navigation
Abilities: Accept a date-time without an offset in the date-time schema format - #86845
Conversation
🤖 PR meta 🤖🎉 PropsIf you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. Props Bot commandsYou can trigger Props Bot actions by commenting on this PR:
Updated as activity occurs, without notifying anyone named here. Add the 📦 Bundle sizeSize Change: +14 B (0%) Total Size: 8.69 MB 📦 View Changed
⚡ PerformanceShow the resultsClient side metrics exclude the server response time. front-end-block-theme
front-end-classic-theme
media-processing
media-upload
post-editor
site-editor
🏁 Flaky testsSome 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
|
…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.
472f3b2 to
9ea77f4
Compare
gziolo
left a comment
There was a problem hiding this comment.
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.
|
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. |
|
Manual backport to |
…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>
…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>
What?
Follow up to #79555.
The client-side validator of
@wordpress/abilitiesnow accepts a date-time without a time zone offset, such as2026-10-21T09:30:00, for thedate-timeschema 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 byexecuteAbility(), which validates the input before it sends the request and the result when it arrives. Fordate-timethe two disagree:rest_parse_date(), where the offset is optional.2026-10-21T09:30:00is valid.date-timecheck ofajv-formats, which follows RFC 3339 and requires the offset.2026-10-21T09:30:00givesInvalid date.A date without an offset is the usual form in WordPress, not an edge case:
date,date_gmt,modifiedandmodified_gmtin that form, and declares them withformat: date-time.datewithout an offset is the time of the site, and adate_gmtwithout an offset is UTC (rest_get_date_with_gmt()).So two kinds of call fail in the client, for values that the server accepts:
format: date-timecannot be called with a date in the time of the site.executeAbility()throwsability_invalid_inputand the request is never sent.mysql_to_rfc3339(), passes validation on the server. The client then throwsability_invalid_output. One such value is enough: the caller gets none of the result.How core abilities use the
date-timeformatAlready in WordPress trunk, in the output:
core/content-query:dateandmodified, each an object withsiteandgmt.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-uploadandcore/media-updatetakedata.date, an object withsite,gmtor both, each withformat: date-time.dateanddate_gmt. With an offset it is that moment. Without an offset,siteis the time of the site andgmtis UTC.With the strict check, the client would refuse exactly that call:
How?
date-timeis no longer in the list of formats given toaddFormats(). It is registered withajv.addFormat( 'date-time', addFormats.get( 'iso-date-time' ) ).iso-date-timeis a format thatajv-formatsalready has: thedate-timecheck with the time zone made optional. There is no new dependency and no new regular expression.The error message does not change:
Invalid date.2026-10-21T09:30:00+01:002026-10-21T08:30:00Z2026-10-21T08:30:00.123Z2026-10-21 09:30:00+01:002026-10-21T09:30:002026-10-21T09:30:00.1232026-10-21 09:30:002026-10-212026-10-21T09:302026-13-01T09:30:00October 21, 2026The change is only the three rows in the middle. Two differences between the client and the server remain, as before:
2026-02-30T09:30:00and2026-10-21T24:00:00are invalid in the client; the server rolls them over to the next valid date.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
npm run test:unit -- packages/abilities/src/tests/validation.test.ts. All tests pass.AI-relevant format validationgroup: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.datewithsiteandgmt, 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:dateanddate_gmtwithout an offset.packages/abilities/src/validation.tsand 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.