[wp-trac] [WordPress Trac] #18998: date/time handling in xml-rpc assumes GMT value

WordPress Trac wp-trac at lists.automattic.com
Wed Oct 19 08:09:16 UTC 2011


#18998: date/time handling in xml-rpc assumes GMT value
--------------------------+-----------------------------
 Reporter:  alien8        |      Owner:
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  XML-RPC       |    Version:  3.2.1
 Severity:  normal        |   Keywords:
--------------------------+-----------------------------
 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.

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/18998>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list