Ticket #35053: 35053-3.patch
File 35053-3.patch, 15.6 KB (added by , 9 years ago) |
---|
-
src/wp-includes/class-wp-xmlrpc-server.php
3427 3427 // We know this is supposed to be GMT, so we're going to slap that Z on there by force 3428 3428 $dateCreated = rtrim( $content_struct['date_created_gmt']->getIso(), 'Z' ) . 'Z'; 3429 3429 $comment_date = iso8601_to_datetime( $dateCreated ); 3430 $comment_date_gmt = get_gmt_from_date( $comment_date);3430 $comment_date_gmt = iso8601_to_datetime( $dateCreated, 'gmt' ); 3431 3431 } 3432 3432 3433 3433 if ( isset($content_struct['content']) ) … … 4998 4998 } 4999 4999 5000 5000 // Do some timestamp voodoo 5001 if ( !empty( $content_struct['date_created_gmt'] ) ) 5001 if ( !empty( $content_struct['date_created_gmt'] ) ) { 5002 5002 // We know this is supposed to be GMT, so we're going to slap that Z on there by force 5003 $dateCreated = rtrim( $content_struct['date_created_gmt']->getIso(), 'Z' ) . 'Z'; 5004 elseif ( !empty( $content_struct['dateCreated']) ) 5005 $dateCreated = $content_struct['dateCreated']->getIso(); 5003 $dateCreated = iso8601_to_datetime( rtrim( $content_struct['date_created_gmt']->getIso(), 'Z' ) . 'Z' ); 5004 } elseif ( !empty( $content_struct['dateCreated']) ) { 5005 $dateCreated = iso8601_to_datetime( $content_struct['dateCreated']->getIso() ); 5006 } 5006 5007 5007 5008 if ( !empty( $dateCreated ) ) { 5008 $post_date = iso8601_to_datetime( $dateCreated );5009 $post_date = $dateCreated; 5009 5010 $post_date_gmt = get_gmt_from_date( $post_date ); 5010 5011 } else { 5011 5012 $post_date = ''; … … 5355 5356 $to_ping = implode(' ', $to_ping); 5356 5357 } 5357 5358 5358 // Do some timestamp voodoo. 5359 if ( !empty( $content_struct['date_created_gmt'] ) ) 5360 // We know this is supposed to be GMT, so we're going to slap that Z on there by force. 5361 $dateCreated = rtrim( $content_struct['date_created_gmt']->getIso(), 'Z' ) . 'Z'; 5362 elseif ( !empty( $content_struct['dateCreated']) ) 5363 $dateCreated = $content_struct['dateCreated']->getIso(); 5359 // Do some timestamp voodoo 5360 if ( !empty( $content_struct['date_created_gmt'] ) ) { 5361 // We know this is supposed to be GMT, so we're going to slap that Z on there by force 5362 $dateCreated = iso8601_to_datetime( rtrim( $content_struct['date_created_gmt']->getIso(), 'Z' ) . 'Z' ); 5363 } elseif ( !empty( $content_struct['dateCreated']) ) { 5364 $dateCreated = iso8601_to_datetime( $content_struct['dateCreated']->getIso() ); 5365 } 5364 5366 5365 5367 if ( !empty( $dateCreated ) ) { 5366 $post_date = iso8601_to_datetime( $dateCreated );5367 $post_date_gmt = get_gmt_from_date( $post_date , 'GMT');5368 $post_date = $dateCreated; 5369 $post_date_gmt = get_gmt_from_date( $post_date ); 5368 5370 } else { 5369 5371 $post_date = $postdata['post_date']; 5370 5372 $post_date_gmt = $postdata['post_date_gmt']; -
src/wp-includes/formatting.php
2680 2680 * @return string The date and time in MySQL DateTime format - Y-m-d H:i:s. 2681 2681 */ 2682 2682 function iso8601_to_datetime( $date_string, $timezone = 'user' ) { 2683 $timezone = strtolower( $timezone);2683 $timezone = strtolower( $timezone ); 2684 2684 2685 if ($timezone == 'gmt') {2685 $tzstring = get_option( 'timezone_string' ); 2686 2686 2687 preg_match('#([0-9]{4})([0-9]{2})([0-9]{2})T([0-9]{2}):([0-9]{2}):([0-9]{2})(Z|[\+|\-][0-9]{2,4}){0,1}#', $date_string, $date_bits); 2687 if ( empty( $tzstring ) ) { 2688 $tzstring = date_default_timezone_get(); 2689 } 2688 2690 2689 if (!empty($date_bits[7])) { // we have a timezone, so let's compute an offset 2690 $offset = iso8601_timezone_to_offset($date_bits[7]); 2691 } else { // we don't have a timezone, so we assume user local timezone (not server's!) 2692 $offset = HOUR_IN_SECONDS * get_option('gmt_offset'); 2693 } 2691 $tz = timezone_open( $tzstring ); 2694 2692 2695 $timestamp = gmmktime($date_bits[4], $date_bits[5], $date_bits[6], $date_bits[2], $date_bits[3], $date_bits[1]); 2696 $timestamp -= $offset; 2693 if ( false === $tz ) { 2694 return '0000-00-00 00:00:00'; 2695 } 2697 2696 2698 return gmdate('Y-m-d H:i:s', $timestamp);2697 $datetime = date_create( $date_string, $tz ); 2699 2698 2700 } elseif ($timezone == 'user') {2701 return preg_replace('#([0-9]{4})([0-9]{2})([0-9]{2})T([0-9]{2}):([0-9]{2}):([0-9]{2})(Z|[\+|\-][0-9]{2,4}){0,1}#', '$1-$2-$3 $4:$5:$6', $date_string);2699 if ( false === $datetime ) { 2700 return '0000-00-00 00:00:00'; 2702 2701 } 2702 2703 if ( 'gmt' === $timezone ) { 2704 date_timezone_set( $datetime, timezone_open( 'UTC' ) ); 2705 } else { 2706 date_timezone_set( $datetime, $tz ); 2707 } 2708 2709 return date_format( $datetime, 'Y-m-d H:i:s' ); 2703 2710 } 2704 2711 2705 2712 /** -
tests/phpunit/tests/formatting/DateTime.php
1 <?php 2 3 /** 4 * @group formatting 5 */ 6 class Tests_Formatting_DateTime extends WP_UnitTestCase { 7 protected $tz; 8 9 function setUp() { 10 $this->tz = get_option( 'timezone_string' ); 11 } 12 13 function tearDown() { 14 update_option( 'timezone_string', $this->tz ); 15 } 16 17 /** 18 * @ticket 35053 19 */ 20 function test_bad_timezone_strings() { 21 update_option( 'timezone_string', '' ); 22 $this->assertEquals( '1984-01-11 05:00:00', iso8601_to_datetime( '1984-01-11T05:00:00', 'gmt' ) ); 23 24 update_option( 'timezone_string', 'garbage' ); // will get set to empty string 25 $this->assertEquals( '1984-01-11 05:00:00', iso8601_to_datetime( '1984-01-11T05:00:00', 'gmt' ) ); 26 } 27 28 /** 29 * @ticket 35053 30 */ 31 function test_invalid_dates() { 32 update_option( 'timezone_string', 'UTC' ); 33 34 $this->assertEquals( '-0001-11-30 00:00:00', iso8601_to_datetime( '0000-00-00T00:00:00Z' ), 'all zeroes' ); 35 $this->assertEquals( '0000-00-00 00:00:00', iso8601_to_datetime( '1984-01-11T05:00:00+XYZ' ), 'invalid TZ' ); 36 } 37 38 function test_utc() { 39 update_option( 'timezone_string', 'UTC' ); 40 41 $date_string = '1984-01-11 05:00:00'; 42 43 $this->assertEquals( $date_string, iso8601_to_datetime( '19840111T05:00:00Z', 'gmt' ), 'Z, gmt' ); 44 $this->assertEquals( $date_string, iso8601_to_datetime( '19840111T03:00:00-0200', 'gmt' ), '-0200, gmt' ); 45 $this->assertEquals( $date_string, iso8601_to_datetime( '19840111T04:00:00-0100', 'gmt' ), '-0100, gmt' ); 46 $this->assertEquals( $date_string, iso8601_to_datetime( '19840111T05:00:00+0000', 'gmt' ), '+0000, gmt' ); 47 $this->assertEquals( $date_string, iso8601_to_datetime( '19840111T06:00:00+0100', 'gmt' ), '+0100, gmt' ); 48 $this->assertEquals( $date_string, iso8601_to_datetime( '19840111T07:00:00+0200', 'gmt' ), '+0200, gmt' ); 49 50 $this->assertEquals( $date_string, iso8601_to_datetime( '19840111T05:00:00Z', 'user' ), 'Z, user' ); 51 $this->assertEquals( $date_string, iso8601_to_datetime( '19840111T03:00:00-0200', 'user' ), '-0200, user' ); 52 $this->assertEquals( $date_string, iso8601_to_datetime( '19840111T04:00:00-0100', 'user' ), '-0100, user' ); 53 $this->assertEquals( $date_string, iso8601_to_datetime( '19840111T05:00:00+0000', 'user' ), '+0000, user' ); 54 $this->assertEquals( $date_string, iso8601_to_datetime( '19840111T06:00:00+0100', 'user' ), '+0100, user' ); 55 $this->assertEquals( $date_string, iso8601_to_datetime( '19840111T07:00:00+0200', 'user' ), '+0200, user' ); 56 } 57 58 /** 59 * @ticket 35053 60 */ 61 function test_america_newyork() { 62 // America/New_York is UTC-05:00 (UTC-04:00 DST) 63 update_option( 'timezone_string', 'America/New_York' ); 64 65 $date_string = '1984-01-11 05:00:00'; 66 67 $this->assertEquals( $date_string, iso8601_to_datetime( '19840111T05:00:00Z', 'gmt' ), 'Z, gmt' ); 68 $this->assertEquals( $date_string, iso8601_to_datetime( '19840111T03:00:00-0200', 'gmt' ), '-0200, gmt' ); 69 $this->assertEquals( $date_string, iso8601_to_datetime( '19840111T04:00:00-0100', 'gmt' ), '-0100, gmt' ); 70 $this->assertEquals( $date_string, iso8601_to_datetime( '19840111T05:00:00+0000', 'gmt' ), '+0000, gmt' ); 71 $this->assertEquals( $date_string, iso8601_to_datetime( '19840111T06:00:00+0100', 'gmt' ), '+0100, gmt' ); 72 $this->assertEquals( $date_string, iso8601_to_datetime( '19840111T07:00:00+0200', 'gmt' ), '+0200, gmt' ); 73 74 $this->assertEquals( $date_string, iso8601_to_datetime( '19840111T10:00:00Z', 'user' ), 'Z, user' ); 75 $this->assertEquals( $date_string, iso8601_to_datetime( '19840111T08:00:00-0200', 'user' ), '-0200, user' ); 76 $this->assertEquals( $date_string, iso8601_to_datetime( '19840111T09:00:00-0100', 'user' ), '-0100, user' ); 77 $this->assertEquals( $date_string, iso8601_to_datetime( '19840111T10:00:00+0000', 'user' ), '+0000, user' ); 78 $this->assertEquals( $date_string, iso8601_to_datetime( '19840111T11:00:00+0100', 'user' ), '+0100, user' ); 79 $this->assertEquals( $date_string, iso8601_to_datetime( '19840111T12:00:00+0200', 'user' ), '+0200, user' ); 80 } 81 82 /** 83 * @ticket 35053 84 */ 85 function test_africa_johannesburg() { 86 // Africa/Johannesburg is UTC+02:00 87 update_option( 'timezone_string', 'Africa/Johannesburg' ); 88 89 $date_string = '1984-01-11 05:00:00'; 90 91 $this->assertEquals( $date_string, iso8601_to_datetime( '19840111T05:00:00Z', 'gmt' ), 'Z, gmt' ); 92 $this->assertEquals( $date_string, iso8601_to_datetime( '19840111T03:00:00-0200', 'gmt' ), '-0200, gmt' ); 93 $this->assertEquals( $date_string, iso8601_to_datetime( '19840111T04:00:00-0100', 'gmt' ), '-0100, gmt' ); 94 $this->assertEquals( $date_string, iso8601_to_datetime( '19840111T05:00:00+0000', 'gmt' ), '+0000, gmt' ); 95 $this->assertEquals( $date_string, iso8601_to_datetime( '19840111T06:00:00+0100', 'gmt' ), '+0100, gmt' ); 96 $this->assertEquals( $date_string, iso8601_to_datetime( '19840111T07:00:00+0200', 'gmt' ), '+0200, gmt' ); 97 98 $this->assertEquals( $date_string, iso8601_to_datetime( '19840111T03:00:00Z', 'user' ), 'Z, user' ); 99 $this->assertEquals( $date_string, iso8601_to_datetime( '19840111T01:00:00-0200', 'user' ), '-0200, user' ); 100 $this->assertEquals( $date_string, iso8601_to_datetime( '19840111T02:00:00-0100', 'user' ), '-0100, user' ); 101 $this->assertEquals( $date_string, iso8601_to_datetime( '19840111T03:00:00+0000', 'user' ), '+0000, user' ); 102 $this->assertEquals( $date_string, iso8601_to_datetime( '19840111T04:00:00+0100', 'user' ), '+0100, user' ); 103 $this->assertEquals( $date_string, iso8601_to_datetime( '19840111T05:00:00+0200', 'user' ), '+0200, user' ); 104 } 105 106 } -
tests/phpunit/tests/xmlrpc/mw/editPost.php
Property changes on: tests/phpunit/tests/formatting/DateTime.php ___________________________________________________________________ Added: svn:executable ## -0,0 +1 ## +* \ No newline at end of property
246 246 } 247 247 248 248 /** 249 * @ticket 35053 250 */ 251 function test_post_date_dateCreated_gmt_timezone_conversion() { 252 $tz = get_option( 'timezone_string' ); 253 update_option( 'timezone_string', 'America/New_York' ); 254 255 $editor_id = $this->make_user_by_role( 'editor' ); 256 257 $post_id = self::factory()->post->create( array( 258 'post_author' => $editor_id 259 ) ); 260 261 $date_string = '1984-01-11 05:00:00'; 262 // America/New_York's time zone is -5:00 so add 5 hours 263 $date_string_gmt = '1984-01-11 10:00:00'; 264 265 $result = $this->myxmlrpcserver->mw_editPost( array( $post_id, 'editor', 'editor', array( 266 'dateCreated' => new IXR_Date( mysql2date( 'Ymd\TH:i:s', $date_string_gmt, false ) . 'Z' ), 267 ) ) ); 268 269 $fetched_post = get_post( $post_id ); 270 271 update_option( 'timezone_string', $tz ); 272 273 $this->assertTrue( $result ); 274 $this->assertEquals( $date_string, $fetched_post->post_date ); 275 } 276 277 /** 278 * @ticket 35053 279 */ 280 function test_post_date_gmt_timezone_conversion() { 281 $tz = get_option( 'timezone_string' ); 282 update_option( 'timezone_string', 'America/New_York' ); 283 284 $editor_id = $this->make_user_by_role( 'editor' ); 285 286 $post_id = self::factory()->post->create( array( 287 'post_author' => $editor_id 288 ) ); 289 290 $date_string = '1984-01-11 05:00:00'; 291 // America/New_York's time zone is -5:00 so add 5 hours 292 $date_string_gmt = '1984-01-11 10:00:00'; 293 294 $result = $this->myxmlrpcserver->mw_editPost( array( $post_id, 'editor', 'editor', array( 295 'date_created_gmt' => new IXR_Date( mysql2date( 'Ymd\TH:i:s', $date_string_gmt, false ) ), 296 ) ) ); 297 298 $fetched_post = get_post( $post_id ); 299 300 update_option( 'timezone_string', $tz ); 301 302 $this->assertTrue( $result ); 303 $this->assertEquals( $date_string, $fetched_post->post_date ); 304 } 305 306 /** 249 307 * @ticket 16980 250 308 */ 251 309 function test_empty_not_null() { -
tests/phpunit/tests/xmlrpc/mw/newPost.php
193 193 $this->assertStringMatchesFormat( '%d', $result ); 194 194 $this->assertEquals( $date_string , $fetched_post->post_date ); 195 195 } 196 197 /** 198 * @ticket 35053 199 */ 200 function test_post_date_dateCreated_gmt_timezone_conversion() { 201 $tz = get_option( 'timezone_string' ); 202 update_option( 'timezone_string', 'America/New_York' ); 203 204 $this->make_user_by_role( 'editor' ); 205 $date_string = '1984-01-11 05:00:00'; 206 // America/New_York's time zone is -5:00 so add 5 hours 207 $date_string_gmt = '1984-01-11 10:00:00'; 208 $post = array( 209 'title' => 'test', 210 'post_content' => 'test', 211 'dateCreated' => new IXR_Date( mysql2date( 'Ymd\TH:i:s', $date_string_gmt, false ) . 'Z' ) 212 ); 213 $result = $this->myxmlrpcserver->mw_newPost( array( 1, 'editor', 'editor', $post ) ); 214 $fetched_post = get_post( $result ); 215 216 update_option( 'timezone_string', $tz ); 217 218 $this->assertStringMatchesFormat( '%d', $result ); 219 $this->assertEquals( $date_string , $fetched_post->post_date ); 220 } 221 222 /** 223 * @ticket 35053 224 */ 225 function test_post_date_gmt_timezone_conversion() { 226 $tz = get_option( 'timezone_string' ); 227 update_option( 'timezone_string', 'America/New_York' ); 228 229 $this->make_user_by_role( 'editor' ); 230 $date_string = '1984-01-11 05:00:00'; 231 // America/New_York's time zone is -5:00 so add 5 hours 232 $date_string_gmt = '1984-01-11 10:00:00'; 233 $post = array( 234 'title' => 'test', 235 'post_content' => 'test', 236 'date_created_gmt' => new IXR_Date( mysql2date( 'Ymd\TH:i:s', $date_string_gmt, false ) ) 237 ); 238 $result = $this->myxmlrpcserver->mw_newPost( array( 1, 'editor', 'editor', $post ) ); 239 $fetched_post = get_post( $result ); 240 241 update_option( 'timezone_string', $tz ); 242 243 $this->assertStringMatchesFormat( '%d', $result ); 244 $this->assertEquals( $date_string , $fetched_post->post_date ); 245 } 246 196 247 } -
tests/phpunit/tests/xmlrpc/wp/editComment.php
91 91 $comment_id = wp_insert_comment( $comment_data ); 92 92 93 93 $date_string = '1984-01-11 05:00:00'; 94 // America/New_York's time zone is -5:00 so add 5 hours 95 $date_string_gmt = '1984-01-11 10:00:00'; 94 96 $result = $this->myxmlrpcserver->wp_editComment( array( 1, 'administrator', 'administrator', $comment_id, array( 95 'date_created_gmt' => new IXR_Date( mysql2date( 'Ymd\TH:i:s', $date_string , false ) )97 'date_created_gmt' => new IXR_Date( mysql2date( 'Ymd\TH:i:s', $date_string_gmt, false ) ) 96 98 ) ) ); 97 99 $fetched_comment = get_comment( $comment_id ); 98 100 … … 101 103 $this->assertTrue( $result ); 102 104 $this->assertEquals( $date_string, $fetched_comment->comment_date ); 103 105 } 104 } 105 No newline at end of file 106 }