Ticket #41782: build-mysql-datetime1.patch
File build-mysql-datetime1.patch, 3.9 KB (added by , 6 years ago) |
---|
-
src/wp-includes/date.php
IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8
865 865 * @return string|false A MySQL format date/time or false on failure 866 866 */ 867 867 public function build_mysql_datetime( $datetime, $default_to_max = false ) { 868 $now = current_time( 'timestamp' );869 868 870 869 if ( ! is_array( $datetime ) ) { 871 870 … … 907 906 908 907 // If no match is found, we don't support default_to_max. 909 908 if ( ! is_array( $datetime ) ) { 910 // @todo Timezone issues here possibly 911 return gmdate( 'Y-m-d H:i:s', strtotime( $datetime, $now ) ); 909 $wp_timezone = wp_timezone(); 910 $dt = date_create( $datetime, $wp_timezone ); // Assume local time zone if not provided. 911 912 if ( false === $dt ) { 913 return gmdate( 'Y-m-d H:i:s', false ); 914 } 915 916 return $dt->setTimezone( $wp_timezone )->format( 'Y-m-d H:i:s' ); 912 917 } 913 918 } 914 919 915 920 $datetime = array_map( 'absint', $datetime ); 916 921 917 922 if ( ! isset( $datetime['year'] ) ) { 918 $datetime['year'] = gmdate( 'Y', $now);923 $datetime['year'] = current_time( 'Y' ); 919 924 } 920 925 921 926 if ( ! isset( $datetime['month'] ) ) { -
tests/phpunit/tests/date/query.php
IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8
509 509 $this->assertSame( $expected, $found ); 510 510 } 511 511 512 public function test_build_mysql_datetime_default_to_max_true() { 513 $q = new WP_Date_Query( array() ); 512 /** 513 * @dataProvider mysql_datetime_input_provider 514 * 515 * @param array|string $datetime Array or string date input. 516 * @param string $result Expected built result. 517 * @param bool $default_to_max Flag to default missing values to max. 518 */ 519 public function test_build_mysql_datetime( $datetime, $result, $default_to_max = false ) { 514 520 515 $found = $q->build_mysql_datetime(516 array(517 'year' => 2011,518 ),519 true520 );521 $this->assertSame( '2011-12-31 23:59:59', $found );522 }523 524 public function test_build_mysql_datetime_default_to_max_false() {525 521 $q = new WP_Date_Query( array() ); 526 522 527 $found = $q->build_mysql_datetime( 528 array( 529 'year' => 2011, 530 ), 531 false 532 ); 533 $this->assertSame( '2011-01-01 00:00:00', $found ); 523 $found = $q->build_mysql_datetime( $datetime, $default_to_max ); 524 525 $message = "Expected {$result}, got {$found}"; 526 $this->assertEquals( strtotime( $result ), strtotime( $found ), $message, 10 ); 534 527 } 535 528 536 public function test_build_mysql_datetime_default_to_max_default_to_false() { 537 $q = new WP_Date_Query( array() ); 529 public function mysql_datetime_input_provider() { 538 530 539 $found = $q->build_mysql_datetime( 540 array( 541 'year' => 2011, 542 ), 543 false 544 ); 545 $this->assertSame( '2011-01-01 00:00:00', $found ); 531 update_option( 'timezone_string', 'Europe/Kiev' ); 532 533 $yesterday = new DateTimeImmutable( '-1 day', wp_timezone() ); 534 535 return [ 536 [ '-1 day', $yesterday->format( 'Y-m-d H:i:s' ) ], 537 [ '2019-06-04T08:18:24+03:00', '2019-06-04 08:18:24' ], 538 [ '2019-06-04T05:18:24+00:00', '2019-06-04 08:18:24' ], 539 [ [], current_time( 'Y' ) . '-01-01 00:00:00' ], 540 [ [ 'year' => 2011 ], '2011-12-31 23:59:59', true ], 541 [ [ 'year' => 2011 ], '2011-01-01 00:00:00' ], 542 [ '2011', '2011-01-01 00:00:00' ], 543 [ '2011-02', '2011-02-01 00:00:00' ], 544 [ '2011-02-03', '2011-02-03 00:00:00' ], 545 [ '2011-02-03 13:30', '2011-02-03 13:30:00' ], 546 [ '2011-02-03 13:30:35', '2011-02-03 13:30:35' ], 547 ]; 546 548 } 547 549 548 550 public function test_build_time_query_insufficient_time_values() {