Ticket #34279: 34279.3.patch
File 34279.3.patch, 3.6 KB (added by , 9 years ago) |
---|
-
src/wp-includes/formatting.php
611 611 . ')*+' // Loop possessively. 612 612 . '(?:]]>)?'; // End of comment. If not found, match all input. 613 613 614 $escaped = 614 $escaped = 615 615 '(?=' // Is the element escaped? 616 616 . '!--' 617 617 . '|' … … 2560 2560 return chr( hexdec( strtolower( $match[1] ) ) ); 2561 2561 } 2562 2562 2563 2563 2564 /** 2564 2565 * Returns a date in the GMT equivalent. 2565 2566 * … … 2572 2573 * 2573 2574 * @param string $string The date to be converted. 2574 2575 * @param string $format The format string for the returned date (default is Y-m-d H:i:s) 2576 * 2575 2577 * @return string GMT version of the date provided. 2576 2578 */ 2577 2579 function get_gmt_from_date( $string, $format = 'Y-m-d H:i:s' ) { … … 2578 2580 $tz = get_option( 'timezone_string' ); 2579 2581 if ( $tz ) { 2580 2582 $datetime = date_create( $string, new DateTimeZone( $tz ) ); 2581 if ( ! $datetime ) 2583 if ( ! $datetime ) { 2582 2584 return gmdate( $format, 0 ); 2585 } 2583 2586 $datetime->setTimezone( new DateTimeZone( 'UTC' ) ); 2584 2587 $string_gmt = $datetime->format( $format ); 2585 2588 } else { 2586 if ( ! preg_match( '#([0-9]{1,4})-([0-9]{1,2})-([0-9]{1,2}) ([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2})#', $string, $matches ) ) 2587 return gmdate( $format, 0 ); 2589 if ( ! preg_match( '#([0-9]{1,4})-([0-9]{1,2})-([0-9]{1,2}) ([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2})#', $string, $matches ) ) { 2590 $datetime = strtotime( $string ); 2591 if ( false === $datetime ) { 2592 return gmdate( $format, 0 ); 2593 } 2594 2595 return gmdate( $format, $datetime ); 2596 } 2588 2597 $string_time = gmmktime( $matches[4], $matches[5], $matches[6], $matches[2], $matches[3], $matches[1] ); 2589 $string_gmt = gmdate( $format, $string_time - get_option( 'gmt_offset' ) * HOUR_IN_SECONDS );2598 $string_gmt = gmdate( $format, $string_time - get_option( 'gmt_offset' ) * HOUR_IN_SECONDS ); 2590 2599 } 2600 2591 2601 return $string_gmt; 2592 2602 } 2593 2603 -
tests/phpunit/tests/formatting/date.php
44 44 function test_get_gmt_from_date_during_dst() { 45 45 update_option( 'timezone_string', 'Europe/London' ); 46 46 $local = '2012-06-01 12:34:56'; 47 $gmt = '2012-06-01 11:34:56';47 $gmt = '2012-06-01 11:34:56'; 48 48 $this->assertEquals( $gmt, get_gmt_from_date( $local ) ); 49 49 } 50 51 /** 52 * @ticket 34279 53 */ 54 function test_get_date_and_time_from_gmt_no_timezone() { 55 $gmt = $local = '2012-01-01 12:34:56'; 56 $this->assertEquals( $gmt, get_date_from_gmt( $local ) ); 57 } 58 59 /** 60 * @ticket 34279 61 */ 62 function test_get_gmt_from_date_no_timezone() { 63 $gmt = '2012-12-01 00:00:00'; 64 $date = '2012-12-01'; 65 $this->assertEquals( $gmt, get_gmt_from_date( $date ) ); 66 } 67 68 69 /** 70 * 71 * @ticket 34279 72 */ 73 function test_get_gmt_from_date_short_date() { 74 update_option( 'timezone_string', 'Europe/London' ); 75 $local = '2012-12-01'; 76 $gmt = '2012-12-01 00:00:00'; 77 $this->assertEquals( $gmt, get_gmt_from_date( $local ) ); 78 } 79 80 /** 81 * 82 * @ticket 34279 83 */ 84 function test_get_gmt_from_date_string_date() { 85 update_option( 'timezone_string', 'Europe/London' ); 86 $local = 'now'; 87 $gmt = gmdate( 'Y-m-d H:i:s', strtotime( 'now' ) ); 88 $this->assertEquals( $gmt, get_gmt_from_date( $local ) ); 89 } 90 91 /** 92 * 93 * @ticket 34279 94 */ 95 function test_get_gmt_from_date_string_date_no_timezone() { 96 $local = 'now'; 97 $gmt = gmdate( 'Y-m-d H:i:s', strtotime( 'now' ) ); 98 $this->assertEquals( $gmt, get_gmt_from_date( $local ) ); 99 } 50 100 }