IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
|
|
|
|
| | 1 | <?php |
| | 2 | |
| | 3 | /** |
| | 4 | * @group date |
| | 5 | * @group datetime |
| | 6 | */ |
| | 7 | class Tests_Date_Wp_Date extends WP_UnitTestCase { |
| | 8 | |
| | 9 | public function test_should_return_false_on_invalid_timestamp() { |
| | 10 | |
| | 11 | $this->assertFalse( wp_date( DATE_RFC3339, 'invalid' ) ); |
| | 12 | } |
| | 13 | } |
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
|
|
|
|
| 163 | 163 | * @return string The date, translated if locale specifies it. |
| 164 | 164 | */ |
| 165 | 165 | function date_i18n( $format, $timestamp_with_offset = false, $gmt = false ) { |
| | 166 | |
| | 167 | $timestamp = $timestamp_with_offset; |
| | 168 | |
| 166 | 169 | // 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 ); |
| | 170 | if ( ! is_numeric( $timestamp ) ) { |
| | 171 | $timestamp = current_time( 'timestamp', $gmt ); |
| | 172 | } |
| 168 | 173 | |
| 169 | 174 | /* |
| 170 | 175 | * This is a legacy implementation quirk that the returned timestamp is also with offset. |
| … |
… |
|
| 218 | 223 | * @param int $timestamp Optional. Unix timestamp. Defaults to current time. |
| 219 | 224 | * @param DateTimeZone $timezone Optional. Timezone to output result in. Defaults to timezone |
| 220 | 225 | * from site settings. |
| 221 | | * @return string The date, translated if locale specifies it. |
| | 226 | * |
| | 227 | * @return string|false The date, translated if locale specifies it. False on invalid timestamp input. |
| 222 | 228 | */ |
| 223 | 229 | function wp_date( $format, $timestamp = null, $timezone = null ) { |
| 224 | 230 | global $wp_locale; |
| 225 | 231 | |
| 226 | | if ( ! $timestamp ) { |
| | 232 | if ( null === $timestamp ) { |
| 227 | 233 | $timestamp = time(); |
| | 234 | } elseif ( ! is_numeric( $timestamp ) ) { |
| | 235 | return false; |
| 228 | 236 | } |
| 229 | 237 | |
| 230 | 238 | if ( ! $timezone ) { |
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
|
|
|
|
| 5 | 5 | * @group datetime |
| 6 | 6 | */ |
| 7 | 7 | class Tests_Date_I18n extends WP_UnitTestCase { |
| | 8 | |
| | 9 | public function test_should_return_current_time_on_invalid_timestamp() { |
| | 10 | $timezone = 'Europe/Kiev'; |
| | 11 | update_option( 'timezone_string', $timezone ); |
| | 12 | $datetime = new DateTime( 'now', new DateTimeZone( $timezone ) ); |
| | 13 | $wp_timestamp = $datetime->getTimestamp() + $datetime->getOffset(); |
| | 14 | |
| | 15 | $this->assertEquals( $wp_timestamp, date_i18n( 'U', 'invalid' ), '', 5 ); |
| | 16 | } |
| | 17 | |
| 8 | 18 | public function test_should_format_date() { |
| 9 | 19 | $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 ); |
| 10 | 20 | } |