| | 615 | * @group strtotime |
| | 616 | */ |
| | 617 | public function test_strtotime_server_timezone_different_than_utc() { |
| | 618 | // Pretend that this is a UTC date. |
| | 619 | $utc_date = '2008-03-25 17:13:55'; |
| | 620 | |
| | 621 | // backup timezone |
| | 622 | $tz_backup = date_default_timezone_get(); |
| | 623 | |
| | 624 | // Pretend server has set timezone to Paris. |
| | 625 | date_default_timezone_set( 'Europe/Paris' ); |
| | 626 | |
| | 627 | $paris_timestamp = strtotime( $utc_date ); |
| | 628 | |
| | 629 | // Set timezone back to UTC. |
| | 630 | date_default_timezone_set( 'UTC' ); |
| | 631 | |
| | 632 | $utc_timestamp = strtotime( $utc_date ); |
| | 633 | |
| | 634 | // revert timezone back to normal |
| | 635 | if ( $tz_backup ) { |
| | 636 | date_default_timezone_set( $tz_backup ); |
| | 637 | } |
| | 638 | |
| | 639 | // Assert that convert Paris time doesn't match original UTC timestamp. |
| | 640 | $this->assertNotSame( $paris_timestamp, $utc_timestamp ); |
| | 641 | } |
| | 642 | |
| | 643 | /** |
| | 644 | * @group strtotime |
| | 645 | */ |
| | 646 | public function test_strtotime_server_timezone_different_but_using_mysql2date_instead_of_strtotime() { |
| | 647 | // Pretend that this is a UTC date. |
| | 648 | $utc_date = '2008-03-25 17:13:55'; |
| | 649 | |
| | 650 | // backup timezone |
| | 651 | $tz_backup = date_default_timezone_get(); |
| | 652 | |
| | 653 | // Pretend server has set timezone to Paris. |
| | 654 | date_default_timezone_set( 'Europe/Paris' ); |
| | 655 | |
| | 656 | $mysql2date = mysql2date( 'G', $utc_date ); |
| | 657 | |
| | 658 | // Set timezone to UTC. |
| | 659 | date_default_timezone_set( 'UTC' ); |
| | 660 | |
| | 661 | $utc_timestamp = strtotime( $utc_date ); |
| | 662 | |
| | 663 | // revert timezone back to normal |
| | 664 | if ( $tz_backup ) { |
| | 665 | date_default_timezone_set( $tz_backup ); |
| | 666 | } |
| | 667 | |
| | 668 | // Assert same even though server timezone is different. |
| | 669 | $this->assertSame( $mysql2date, $utc_timestamp ); |
| | 670 | } |
| | 671 | |
| | 672 | /** |