Ticket #37910: 37910.2.diff
File 37910.2.diff, 4.5 KB (added by , 4 years ago) |
---|
-
src/wp-includes/functions.php
diff --git src/wp-includes/functions.php src/wp-includes/functions.php index 292abf9..e594327 100644
function date_i18n( $dateformatstring, $unixtimestamp = false, $gmt = false ) { 91 91 $i = $unixtimestamp; 92 92 93 93 if ( false === $i ) { 94 if ( ! $gmt ) 95 $i = current_time( 'timestamp' ); 96 else 97 $i = time(); 98 // we should not let date() interfere with our 99 // specially computed timestamp 100 $gmt = true; 94 $i = current_time( 'timestamp', $gmt ); 101 95 } 102 96 103 97 /* … … function date_i18n( $dateformatstring, $unixtimestamp = false, $gmt = false ) { 106 100 */ 107 101 $req_format = $dateformatstring; 108 102 109 $datefunc = $gmt? 'gmdate' : 'date';110 111 103 if ( ( !empty( $wp_locale->month ) ) && ( !empty( $wp_locale->weekday ) ) ) { 112 $datemonth = $wp_locale->get_month( $datefunc( 'm', $i ) );104 $datemonth = $wp_locale->get_month( date( 'm', $i ) ); 113 105 $datemonth_abbrev = $wp_locale->get_month_abbrev( $datemonth ); 114 $dateweekday = $wp_locale->get_weekday( $datefunc( 'w', $i ) );106 $dateweekday = $wp_locale->get_weekday( date( 'w', $i ) ); 115 107 $dateweekday_abbrev = $wp_locale->get_weekday_abbrev( $dateweekday ); 116 $datemeridiem = $wp_locale->get_meridiem( $datefunc( 'a', $i ) );117 $datemeridiem_capital = $wp_locale->get_meridiem( $datefunc( 'A', $i ) );108 $datemeridiem = $wp_locale->get_meridiem( date( 'a', $i ) ); 109 $datemeridiem_capital = $wp_locale->get_meridiem( date( 'A', $i ) ); 118 110 $dateformatstring = ' '.$dateformatstring; 119 111 $dateformatstring = preg_replace( "/([^\\\])D/", "\\1" . backslashit( $dateweekday_abbrev ), $dateformatstring ); 120 112 $dateformatstring = preg_replace( "/([^\\\])F/", "\\1" . backslashit( $datemonth ), $dateformatstring ); … … function date_i18n( $dateformatstring, $unixtimestamp = false, $gmt = false ) { 142 134 } 143 135 } 144 136 } 145 $j = @ $datefunc( $dateformatstring, $i );137 $j = @date( $dateformatstring, $i ); 146 138 147 139 /** 148 140 * Filters the date formatted based on the locale. … … function do_enclose( $content, $post_ID ) { 563 555 global $wpdb; 564 556 565 557 //TODO: Tidy this ghetto code up and make the debug code optional 566 include_once( ABSPATH . WPINC . '/class-IXR.php' ); 558 include_once( ABSPATH . WPINC . '/class-IXR.php' ); 567 559 568 560 $post_links = array(); 569 561 -
new file tests/phpunit/tests/date/dateI18n.php
diff --git tests/phpunit/tests/date/dateI18n.php tests/phpunit/tests/date/dateI18n.php new file mode 100644 index 0000000..108bd94
- + 1 <?php 2 3 /** 4 * @group date 5 * @group datetime 6 */ 7 class Tests_Date_I18n extends WP_UnitTestCase { 8 public function test_should_format_date() { 9 $expected = date( 'Y-m-d H:i:s' ); 10 $this->assertEquals( $expected, date_i18n( 'Y-m-d H:i:s' ) ); 11 } 12 13 public function test_should_use_custom_timestamp() { 14 $expected = '2012-12-01 00:00:00'; 15 16 $this->assertEquals( $expected, date_i18n( 'Y-m-d H:i:s', strtotime( '2012-12-01 00:00:00' ) ) ); 17 } 18 19 public function test_date_should_be_in_gmt() { 20 $expected = date( 'Y-m-d H:i:s' ); 21 22 $this->assertEquals( $expected, date_i18n( 'Y-m-d H:i:s', false, true ) ); 23 } 24 25 public function test_custom_timestamp_ignores_gmt_setting() { 26 $expected = '2012-12-01 00:00:00'; 27 28 $this->assertEquals( $expected, date_i18n( 'Y-m-d H:i:s', strtotime( '2012-12-01 00:00:00' ), false ) ); 29 } 30 31 public function test_custom_timezone_setting() { 32 update_option( 'timezone_string', 'Europe/London' ); 33 $expected = date( 'Y-m-d H:i:s', strtotime( date( 'Y-m-d H:i:s' ) ) + HOUR_IN_SECONDS ); 34 35 $this->assertEquals( $expected, date_i18n( 'Y-m-d H:i:s' ) ); 36 } 37 38 public function test_date_should_be_in_gmt_with_custom_timezone_setting() { 39 update_option( 'timezone_string', 'Europe/London' ); 40 $expected = date( 'Y-m-d H:i:s' ); 41 42 $this->assertNotEquals( date_i18n( 'Y-m-d H:i:s', false, false ), date_i18n( 'Y-m-d H:i:s', false, true ) ); 43 $this->assertEquals( $expected, date_i18n( 'Y-m-d H:i:s', false, true ) ); 44 } 45 46 public function test_date_should_be_in_gmt_with_custom_timezone_setting_and_timestamp() { 47 update_option( 'timezone_string', 'Europe/London' ); 48 49 $expected = '2012-12-01 00:00:00'; 50 51 $this->assertEquals( $expected, date_i18n( 'Y-m-d H:i:s', strtotime( '2012-12-01 00:00:00' ), false ) ); 52 $this->assertEquals( $expected, date_i18n( 'Y-m-d H:i:s', strtotime( '2012-12-01 00:00:00' ), true ) ); 53 } 54 55 public function test_adjusts_format_based_on_locale() { 56 $locale = clone $GLOBALS['wp_locale']; 57 58 // Change $GLOBALS['wp_locale'] 59 60 $GLOBALS['wp_locale'] = $locale; 61 62 $this->markTestIncomplete( 'Work in progress' ); 63 } 64 }