REST API: Multiple issues with setting dates of posts
|Reported by:||jnylen0||Owned by:||jnylen0|
|Component:||REST API||Keywords:||has-unit-tests has-patch fixed-major|
Setting the date of a post while creating or updating it is broken in at least two ways.
First, the value that comes back from the API does not contain a timezone (some recent discussion about this in Slack). This is not great, but possibly reasonable, since these values are stored in the database without a timezone offset.
However, when these values are pushed back to the date field of a post via the API, they are interpreted as GMT by the `rest_parse_date` function.
This means that whenever you set the date of a post based on the value that came back from the API, it ends up offset by the site's gmt_offset. Example requests (read in reverse order):
Second, it's impossible to update the date of a draft - the request succeeds but the date is not changed. I haven't yet looked into why this is broken. Creating a draft with a specific date seems to work, though I think it may break core's flag for updating a post's date when the post changes (see "complication" below).
To address the first issue, we need to stop interpreting dates without timezones as UTC, and I think we should also include our best guess for the timezone offset with each date value. (For date this will be the site's gmt_offset, which is not currently available anywhere in the API; for date_gmt this will be zero).
One complication in addressing the second issue is that WP core uses a zero/null date_gmt to indicate that the date field should be updated when a draft is saved. See also #38883 and ticket:5698#comment:14
I'll work on a full patch next, but since it seems likely we'll need to discuss the best approach, I'm starting this ticket off with failing test cases first. We also need tests for rest_parse_date, rest_get_date_with_gmt, and any other related methods.
Change History (22)
- Keywords commit added
- Keywords fixed-major added; commit removed
- Resolution fixed deleted
- Status changed from closed to reopened