Changeset 45914
- Timestamp:
- 08/29/2019 11:17:30 PM (5 years ago)
- Location:
- trunk
- Files:
-
- 1 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/functions.php
r45909 r45914 164 164 */ 165 165 function date_i18n( $format, $timestamp_with_offset = false, $gmt = false ) { 166 $timestamp = $timestamp_with_offset; 167 166 168 // If timestamp is omitted it should be current time (summed with offset, unless `$gmt` is true). 167 $timestamp = $timestamp_with_offset ? $timestamp_with_offset : current_time( 'timestamp', $gmt ); 169 if ( ! is_numeric( $timestamp ) ) { 170 $timestamp = current_time( 'timestamp', $gmt ); 171 } 168 172 169 173 /* … … 219 223 * @param DateTimeZone $timezone Optional. Timezone to output result in. Defaults to timezone 220 224 * from site settings. 221 * @return string The date, translated if locale specifies it.225 * @return string|false The date, translated if locale specifies it. False on invalid timestamp input. 222 226 */ 223 227 function wp_date( $format, $timestamp = null, $timezone = null ) { 224 228 global $wp_locale; 225 229 226 if ( !$timestamp ) {230 if ( null === $timestamp ) { 227 231 $timestamp = time(); 232 } elseif ( ! is_numeric( $timestamp ) ) { 233 return false; 228 234 } 229 235 -
trunk/tests/phpunit/tests/date/currentTime.php
r45857 r45914 5 5 * @group datetime 6 6 */ 7 class Tests_Date_Current Time extends WP_UnitTestCase {7 class Tests_Date_Current_Time extends WP_UnitTestCase { 8 8 9 9 /** -
trunk/tests/phpunit/tests/date/dateI18n.php
r45902 r45914 6 6 */ 7 7 class Tests_Date_I18n extends WP_UnitTestCase { 8 9 /** 10 * @ticket 28636 11 */ 12 public function test_should_return_current_time_on_invalid_timestamp() { 13 $timezone = 'Europe/Kiev'; 14 update_option( 'timezone_string', $timezone ); 15 16 $datetime = new DateTime( 'now', new DateTimeZone( $timezone ) ); 17 $wp_timestamp = $datetime->getTimestamp() + $datetime->getOffset(); 18 19 $this->assertEquals( $wp_timestamp, date_i18n( 'U', 'invalid' ), '', 5 ); 20 } 21 8 22 public function test_should_format_date() { 9 23 $this->assertEquals( strtotime( gmdate( 'Y-m-d H:i:s' ) ), strtotime( date_i18n( 'Y-m-d H:i:s' ) ), 'The dates should be equal', 2 ); … … 75 89 $offset = $datetimezone->getOffset( new DateTime() ) / 3600; 76 90 update_option( 'gmt_offset', $offset ); 91 77 92 $datetime = new DateTime( 'now', $datetimezone ); 78 93 $datetime = new DateTime( $datetime->format( 'P' ) ); -
trunk/tests/phpunit/tests/date/theDate.php
r45379 r45914 5 5 * @group datetime 6 6 */ 7 class Tests_Date_The Date extends WP_UnitTestCase {7 class Tests_Date_The_Date extends WP_UnitTestCase { 8 8 9 9 /** @var array $hooks_called Count of hooks called. */ -
trunk/tests/phpunit/tests/date/wpTimezone.php
r45855 r45914 5 5 * @group datetime 6 6 */ 7 class Tests_ WP_Timezone extends WP_UnitTestCase {7 class Tests_Date_WP_Timezone extends WP_UnitTestCase { 8 8 9 9 /**
Note: See TracChangeset
for help on using the changeset viewer.