Make WordPress Core

Opened 13 years ago

Closed 9 years ago

#18998 closed defect (bug) (duplicate)

date/time handling in xml-rpc assumes GMT value

Reported by: alien8's profile alien8 Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.2.1
Component: XML-RPC Keywords: needs-refresh
Focuses: Cc:

Description

When trying to set post publication times via XML-RPC I noticed that the dateCreated value was assumed to be GMT.

one section of code:

                // Do some timestamp voodoo
                if ( !empty( $content_struct['date_created_gmt'] ) )
                        $dateCreated = str_replace( 'Z', '', $content_struct['date_created_gmt']->getIso() ) . 'Z'; // We know this is supposed to be GMT, so we're going to slap that Z on there by force
                elseif ( !empty( $content_struct['dateCreated']) )
                        $dateCreated = $content_struct['dateCreated']->getIso();

                if ( !empty( $dateCreated ) ) {
                        $post_date = get_date_from_gmt(iso8601_to_datetime($dateCreated));
                        $post_date_gmt = iso8601_to_datetime($dateCreated, 'GMT');
                } else {
                        $post_date = current_time('mysql');
                        $post_date_gmt = current_time('mysql', 1);
                }

in the following part:

                if ( !empty( $dateCreated ) ) {
                        $post_date = get_date_from_gmt(iso8601_to_datetime($dateCreated));
                        $post_date_gmt = iso8601_to_datetime($dateCreated, 'GMT');
                } else {

$post_date is set to GMT (get_date_from_gmt()) value of $dateCreated (assuming it's GMT)
and then $post_date_gmt is set to GMT ...

this forces both values to be identical and assumed to be GMT. this also breaks the ability to set the timezone in the value of dateCreated even though the ISO8061 spec allows it.

I've attached a patch to class-wp-xmlrpc-server.php which appears to fix this problem and allows future published posts to publish properly at the expected date/time.

to duplicate, use an XML-RPC client (I'm using a Perl script) to add a new post and set the dateCreated to a dateTime.iso8061 entity with the value of '20111019T19:05:00+0900' (or something equivlent for your timezone which would be easy to identify as an incorrect value if so.) the publish date of the new post will be the GMT value.

A workaround would be to do all the GMT conversion in the client prior to sending via XML-RPC, but that would make it seem that dateCreated and date_created_gmt will always be duplicate. I've included a patch in case this wasn't an intentional design decision.

Attachments (1)

class-wp-xmlrpc-server.diff (1.5 KB) - added by alien8 13 years ago.

Download all attachments as: .zip

Change History (5)

#1 @josephscott
13 years ago

I strongly recommend using the date_created_gmt field instead of dateCreated.

#2 @DrewAPicture
13 years ago

Related: #19733

Version 0, edited 13 years ago by DrewAPicture (next)

#3 @chriscct7
10 years ago

  • Keywords needs-refresh added

Patch needs a refresh because of whitespace changes

#4 @chriscct7
9 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to duplicate
  • Status changed from new to closed

Duplicate of #30429.

Note: See TracTickets for help on using tickets.