Opened 8 years ago
Last modified 10 months ago
#41032 new defect (bug)
REST API: Date fields do not support ISO8601
| Reported by: |
|
Owned by: | |
|---|---|---|---|
| Milestone: | Future Release | Priority: | normal |
| Severity: | normal | Version: | |
| Component: | REST API | Keywords: | has-unit-tests has-patch |
| Focuses: | docs, rest-api | Cc: |
Description
The post and comment date and date_gmt fields as well as a couple of others like the post before and after fields claim to support ISO8601 but this is not entirely accurate.
The actual format supported is that handled by the `rest_parse_date` function: YYYY-MM-DDTHH:MM:SS plus optional fractional seconds plus an optional timezone specifier in the form Z, +XX, -XX, +XX:XX, or -XX:XX.
Additionally, WordPress behavior around timezones is complicated and poorly specified. The post_date database field is stored in the site's current timezone, and how to interact with this using before and after in particular is not clear. (The best way to do it is probably to avoid specifying a timezone string at all for these values, unless the site's timezone is known by the API client and specified exactly.)
All of this needs to be documented at https://developer.wordpress.org/rest-api/ and any missing test cases added.
Attachments (3)
Change History (9)
#2
follow-up:
↓ 4
@
7 years ago
- Keywords has-unit-tests has-patch added; needs-unit-tests removed
Looks like I uploaded extra files because i used the $ grunt upload_patch:41032command. Will need to fix that...
I modified the tests test_rest_parse_date and test_rest_parse_date_force_utcto assertNotFalse instead of assertEquals because I am getting different unix timestamps for strtotime(...) used in the rest_parse_date function in wp-includes/rest-api.php and the gmmktime(...) function for testing in phpunit/tests/rest-api.php For instance
php > echo gmmktime( 0, 0, 0, 1, 16, 2017 );
1484524800
php > echo strtotime( '2017-01-16' );
1484542800
php > echo strtotime( '2017-01-16T' );
1484550000
are all valid strings and it is sufficient to just assertTrue.
This also seems to respond to #38614
Reference:
ISO8601 validation https://www.myintervals.com/blog/2009/05/20/iso-8601-date-validation-that-doesnt-suck/
regex tester for ISO8601 validation https://www.regextester.com/97766
This ticket was mentioned in Slack in #core-restapi by nickylimjj. View the logs.
7 years ago
#4
in reply to:
↑ 2
@
7 years ago
Replying to nickylimjj:
Looks like I uploaded extra files because i used the
$ grunt upload_patch:41032command. Will need to fix that...
Fixed.
This ticket was mentioned in Slack in #core-restapi by nickylimjj. View the logs.
6 years ago
#6
@
10 months ago
One small note: the code comment on rest_parse_date() currently says that it accepts a date string in RFC3339 format, but that's not entirely accurate. RFC3339 is case-insensitive, while the function's regex only matches a capital Z for the timezone segment. Hence valid strings like 2025-02-06t14:26:23z will be rejected.
Attempted a patch for a better regex string, for ISO8601 validation referenced here: https://www.myintervals.com/blog/2009/05/20/iso-8601-date-validation-that-doesnt-suck/.
Will attempt the missing test cases.