Make WordPress Core

Opened 10 years ago

Closed 5 years ago

Last modified 5 years ago

#30429 closed defect (bug) (fixed)

wp.newPost gets non-GMT date calculation wrong

Reported by: smerriman's profile smerriman Owned by: wonderboymusic's profile wonderboymusic
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)

30429.patch (570 bytes) - added by smerriman 10 years ago.
Renaming patch to ticket number
30429.test.patch (991 bytes) - added by justdaiv 10 years ago.
Unit test
30429.2.patch (570 bytes) - added by smerriman 10 years ago.
30429.3.patch (2.1 KB) - added by smerriman 10 years ago.
Sorry, attached the wrong file.
30429.diff (6.7 KB) - added by wonderboymusic 9 years ago.
30429-xmlrpc-date-inputs.patch (7.8 KB) - added by Rarst 5 years ago.

Download all attachments as: .zip

Change History (31)

@smerriman
10 years ago

Renaming patch to ticket number

#1 @smerriman
10 years ago

  • Component changed from General to XML-RPC
  • Keywords has-patch added

#2 @johnbillion
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 @smerriman
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 @smerriman
10 years ago

  • Severity changed from normal to critical

This bug causes wp.newpost to be completely unusable. Can it be looked at?

@justdaiv
10 years ago

Unit test

#5 @justdaiv
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?

#6 @smerriman
10 years ago

It looks like this is due to: #25399

#7 @smerriman
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.

@smerriman
10 years ago

@smerriman
10 years ago

Sorry, attached the wrong file.

#8 @wonderboymusic
9 years ago

  • Keywords needs-testing removed
  • Milestone changed from Awaiting Review to 4.4

@wonderboymusic
9 years ago

#9 @wonderboymusic
9 years ago

  • Owner set to wonderboymusic
  • Resolution set to fixed
  • Status changed from new to closed

In 34681:

XML-RPC: calculate the proper offset for GMT in wp.newPost, mw.newPost, and mw.editPost when post_date is set, wp.editComment when comment_date is set. post|comment_date is assumed to be GMT. This is only true if the timezone string for the site matches GMT.

Adds unit tests for each.

Props smerriman, justdaiv, wonderboymusic.
Fixes #30429.

#10 @chriscct7
9 years ago

#18998 was marked as a duplicate.

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

#13 @nacin
9 years ago

In 36163:

XML-RPC: Revert [34681] as it broke date handling.

props dossy, hnle, redsweater.
see #35053, #30429 (original ticket).

#14 @nacin
9 years ago

In 36164:

XML-RPC: Revert [34681] as it broke date handling.

Merges [36163] to the 4.4 branch.

props dossy, hnle, redsweater.
see #35053, #30429 (original ticket).

#15 @ocean90
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

This ticket was mentioned in Slack in #core by chriscct7. View the logs.


9 years ago

#17 @chriscct7
9 years ago

  • Milestone changed from 4.5 to Future Release

Punting due to lack of activity per slack discussion 6 days ago.

#18 @Rarst
6 years ago

  • Component changed from XML-RPC to Date/Time
  • Severity changed from critical to normal

#19 @Rarst
5 years ago

#48886 was marked as a duplicate.

#20 @Rarst
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.

This ticket was mentioned in Slack in #core-datetime by rarst. View the logs.


5 years ago

#22 @Rarst
5 years ago

  • Milestone set to 5.3.1

#23 @SergeyBiryukov
5 years ago

  • Resolution set to fixed
  • Status changed from reopened to closed

In 46864:

Date/Time: XML-RPC: Сalculate the proper offset for GMT in wp.newPost, wp.editComment, mw.newPost, mw.editPost when post_date or comment_date is set.

Previously, post_date or comment_date was assumed to be GMT, which is only true if the timezone string for the site matches GMT.

Add unit tests.

Props Rarst, smerriman, justdaiv, wonderboymusic, noyle.
Fixes #30429.

#24 @SergeyBiryukov
5 years ago

In 46865:

Date/Time: XML-RPC: Сalculate the proper offset for GMT in wp.newPost, wp.editComment, mw.newPost, mw.editPost when post_date or comment_date is set.

Previously, post_date or comment_date was assumed to be GMT, which is only true if the timezone string for the site matches GMT.

Add unit tests.

Props Rarst, smerriman, justdaiv, wonderboymusic, noyle.
Merges [46864] to the 5.3 branch.
Fixes #30429.

This ticket was mentioned in Slack in #core-datetime by redsweater. View the logs.


5 years ago

Note: See TracTickets for help on using tickets.