Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use date_Create that does not throw exception or warning #2340

Merged
merged 1 commit into from
Sep 8, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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