#30429 closed defect (bug) (fixed)
wp.newPost gets non-GMT date calculation wrong
Reported by: |
|
Owned by: |
|
---|---|---|---|
Milestone: | 5.3.1 | Priority: | normal |
Severity: | normal | Version: | 3.4 |
Component: | Date/Time | Keywords: | has-patch has-unit-tests |
Focuses: | Cc: |
Description
In class-wp-xmlrpc-server.php, there is a bug with the calculation of dates if a post_date is set.
if ( ! empty( $dateCreated ) ) { $post_data['post_date'] = get_date_from_gmt( iso8601_to_datetime( $dateCreated ) ); $post_data['post_date_gmt'] = iso8601_to_datetime( $dateCreated, 'GMT' ); }
get_date_from_gmt
assumes the parameter passed is a GMT string. iso8601_to_datetime( $dateCreated )
, however, is the local time. It should have the GMT parameter as per the next line to ensure the two dates are always in sync; currently the first one is always incorrect.
Attachments (6)
Change History (31)
#2
@
10 years ago
- Keywords needs-testing reporter-feedback needs-unit-tests added
- Version changed from trunk to 3.4
Thanks for the report. Can you provide some example code or an example XML-RPC request which demonstrates the issue?
The patch will benefit from some unit tests too.
#3
@
10 years ago
- Keywords reporter-feedback removed
Sure. As a specific example, set the Wordpress timezone to Pacific/Auckland (currently GMT+13), and run the following code from the root dir (altering domain/user/pass as appropriate):
<?php include('./wp-load.php'); include_once( ABSPATH . WPINC . '/class-IXR.php' ); include_once( ABSPATH . WPINC . '/class-wp-http-ixr-client.php' ); $client = new WP_HTTP_IXR_CLIENT( 'http://www.domain.com/xmlrpc.php' ); $content = array( 'post_type'=>'post', 'post_title'=>'Test post', 'post_status'=>'publish', 'post_author'=>1, 'post_date'=>'2014-12-01 12:00:00' ); $client->query('wp.newPost','','username','password',$content,true);
The resulting dates in the database will be:
post_date_gmt: 2014-11-30 23:00:00 (correct)
post_date: 2014-12-02 01:00:00 (13 hours later than it should be)
Not experienced enough with organising unit tests myself yet sorry!sorry!
#4
@
10 years ago
- Severity changed from normal to critical
This bug causes wp.newpost to be completely unusable. Can it be looked at?
#5
@
10 years ago
I believe the code patch provided only fixes the case where the local timezone is not in daylight savings time. The unit test I uploaded has the timezone set to America/New_York (which currently is in dst) and the test fails. If I change the unit test to have a timezone of America/Phoenix (where it is never dst), the test passes.
Or am I missing something?
#7
@
10 years ago
Here's an updated patch which should fix the problem properly (and also updates a few other similar places in the same file). It converts the ISO date to the date variable directly; then uses get_gmt_from_date
to calculate the GMT date, rather than the opposite way around. That avoids complications with timezones.
#9
@
9 years ago
- Owner set to wonderboymusic
- Resolution set to fixed
- Status changed from new to closed
In 34681:
This ticket was mentioned in Slack in #core by hinaloe. View the logs.
9 years ago
This ticket was mentioned in Slack in #core by redsweater. View the logs.
9 years ago
#15
@
9 years ago
- Keywords needs-patch added; has-patch removed
- Milestone changed from 4.4 to 4.5
- Resolution fixed deleted
- Status changed from closed to reopened
See https://core.trac.wordpress.org/ticket/35053#comment:33 and the revert.
This ticket was mentioned in Slack in #core by chriscct7. View the logs.
9 years ago
#17
@
9 years ago
- Milestone changed from 4.5 to Future Release
Punting due to lack of activity per slack discussion 6 days ago.
#18
@
6 years ago
- Component changed from XML-RPC to Date/Time
- Severity changed from critical to normal
#20
@
5 years ago
- Keywords has-patch has-unit-tests added; needs-unit-tests needs-patch removed
Ok after 5.3 this was reported again as... Broken? Still broken? Again broken?
Since I rewrote iso8601_to_datetime()
to be less of a mess, in some places the errors likely stopped cancelling each other out.
Attaching a stab at updated unit test and a patch.
Renaming patch to ticket number