From a547653ebe4faf8f6502fa0a9be962e60af969b7 Mon Sep 17 00:00:00 2001 From: Burhan Nasir Date: Fri, 3 Jun 2022 19:19:09 +0500 Subject: [PATCH 1/3] Restrict to convert meta if year is greate than 2099 --- includes/classes/Indexable.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/includes/classes/Indexable.php b/includes/classes/Indexable.php index 3f9f882322..eea77aadc7 100644 --- a/includes/classes/Indexable.php +++ b/includes/classes/Indexable.php @@ -723,10 +723,14 @@ public function prepare_date_meta_values( $meta_types, $meta_value ) { if ( $new_date ) { $timestamp = $new_date->getTimestamp(); + // date_create converts 5479516sunt meta into 107039-03-10. We keep using default values + // if year in date is greater than 2099. + $max_year = 2099; + // PHP allows DateTime to build dates with the non-existing year 0000, and this causes // issues when integrating into stricter systems. This is by design: // https://bugs.php.net/bug.php?id=60288 - if ( false !== $timestamp && '0000' !== $new_date->format( 'Y' ) ) { + if ( false !== $timestamp && '0000' !== $new_date->format( 'Y' ) && $new_date->format( 'Y' ) <= $max_year ) { $meta_types['date'] = $new_date->format( 'Y-m-d' ); $meta_types['datetime'] = $new_date->format( 'Y-m-d H:i:s' ); $meta_types['time'] = $new_date->format( 'H:i:s' ); From dbd5b24823c42d98c1b0e39905e50b721ddccba3 Mon Sep 17 00:00:00 2001 From: Burhan Nasir Date: Wed, 8 Jun 2022 14:52:31 +0500 Subject: [PATCH 2/3] Feedback addressed --- includes/classes/Indexable.php | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/includes/classes/Indexable.php b/includes/classes/Indexable.php index eea77aadc7..9d8f3e1f91 100644 --- a/includes/classes/Indexable.php +++ b/includes/classes/Indexable.php @@ -723,9 +723,16 @@ public function prepare_date_meta_values( $meta_types, $meta_value ) { if ( $new_date ) { $timestamp = $new_date->getTimestamp(); - // date_create converts 5479516sunt meta into 107039-03-10. We keep using default values - // if year in date is greater than 2099. - $max_year = 2099; + /** + * Filter the maximum year limit for date conversion. + * + * @hook ep_max_year_limit + * @param {int} $year Maximum year limit. + * @return {int} Maximum year limit. + */ + // Use default date if year is greater than max limit. EP has limitation that doesn't allow to have year greater than 2099. + // @see https://github.com/10up/ElasticPress/issues/2769 + $max_year = apply_filters( 'ep_max_year_limit', 2099 ); // PHP allows DateTime to build dates with the non-existing year 0000, and this causes // issues when integrating into stricter systems. This is by design: From 1a2a3d6650c4fdc849349e3f1a183935e211eab3 Mon Sep 17 00:00:00 2001 From: Burhan Nasir Date: Tue, 14 Jun 2022 10:51:18 +0500 Subject: [PATCH 3/3] Feedback addressed --- includes/classes/Indexable.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/includes/classes/Indexable.php b/includes/classes/Indexable.php index 9d8f3e1f91..60a768c26d 100644 --- a/includes/classes/Indexable.php +++ b/includes/classes/Indexable.php @@ -726,12 +726,15 @@ public function prepare_date_meta_values( $meta_types, $meta_value ) { /** * Filter the maximum year limit for date conversion. * + * Use default date if year is greater than max limit. EP has limitation that doesn't allow to have year greater than 2099. + * + * @see https://github.com/10up/ElasticPress/issues/2769 + * * @hook ep_max_year_limit * @param {int} $year Maximum year limit. * @return {int} Maximum year limit. + * @since 4.2.1 */ - // Use default date if year is greater than max limit. EP has limitation that doesn't allow to have year greater than 2099. - // @see https://github.com/10up/ElasticPress/issues/2769 $max_year = apply_filters( 'ep_max_year_limit', 2099 ); // PHP allows DateTime to build dates with the non-existing year 0000, and this causes