Skip to content

Commit

Permalink
Merge pull request #2340 from Automattic/update/warnings_meta_upstream
Browse files Browse the repository at this point in the history
Use date_Create that does not throw exception or warning
  • Loading branch information
felipeelia authored Sep 8, 2021
2 parents 21e9c00 + 9e13a3d commit e4194a6
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions includes/classes/Indexable.php
Original file line number Diff line number Diff line change
Expand Up @@ -477,9 +477,9 @@ public function prepare_date_meta_values( $meta_types, $meta_value ) {
$meta_types['datetime'] = '1970-01-01 00:00:01';
$meta_types['time'] = '00:00:01';

try {
// is this is a recognizable date format?
$new_date = new \DateTime( $meta_value, \wp_timezone() );
// is this is a recognizable date format?
$new_date = date_create( $meta_value, \wp_timezone() );
if ( $new_date ) {
$timestamp = $new_date->getTimestamp();

// PHP allows DateTime to build dates with the non-existing year 0000, and this causes
Expand All @@ -490,9 +490,6 @@ public function prepare_date_meta_values( $meta_types, $meta_value ) {
$meta_types['datetime'] = $new_date->format( 'Y-m-d H:i:s' );
$meta_types['time'] = $new_date->format( 'H:i:s' );
}
} catch ( \Exception $e ) {
// if $meta_value is not a recognizable date format, DateTime will throw an exception,
// just catch it and move on.
}

return $meta_types;
Expand Down

0 comments on commit e4194a6

Please sign in to comment.