[wp-trac] [WordPress Trac] #20942: get_gmt_from_date() throws exceptions

WordPress Trac wp-trac at lists.automattic.com
Wed Jun 13 17:45:27 UTC 2012


#20942: get_gmt_from_date() throws exceptions
--------------------------+-----------------------------
 Reporter:  mdawaffe      |      Owner:
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  Date/Time     |    Version:
 Severity:  normal        |   Keywords:
--------------------------+-----------------------------
 As of PHP 5.3, {{{new DateTime( $string )}}} throws an exception if
 {{{$string}}} is unparseable.  WordPress doesn't catch the exception.

 We should either catch the exception or use {{{date_create( $string )}}},
 which just returns false if {{{$string}}} is unparseable.

 I don't know what we should return from {{{get_gmt_from_date( $string )}}}
 if {{{$string}}} is unparseable.  false? 1970? "0000-00-00 00:00:00"? In
 the branch that handles an empty {{{$tz}}}, WordPress usually returns
 something near "1999-11-30 00:00:00" when {{{$string}}} doesn't match the
 expected format.

 ----

 {{{
 $ php -r 'define( "WP_DEBUG_DISPLAY", true ); require "wp-load.php";
 add_filter( "pre_option_timezone_string", function() { return
 "America/Los_Angeles"; } ); var_dump( get_gmt_from_date( "WordPress" ) );'
 PHP Fatal error:  Uncaught exception 'Exception' with message
 'DateTime::__construct(): Failed to parse time string (WordPress) at
 position 0 (W): The timezone could not be found in the database' in
 /Users/mdawaffe/Sites/wordpress/wp-includes/formatting.php:1872
 Stack trace:
 #0 /Users/mdawaffe/Sites/wordpress/wp-includes/formatting.php(1872):
 DateTime->__construct('WordPress')
 #1 Command line code(1): get_gmt_from_date('WordPress')
 #2 {main}
   thrown in /Users/mdawaffe/Sites/wordpress/wp-includes/formatting.php on
 line 1872
 }}}

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/20942>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list