jenkins-bot has submitted this change and it was merged.

Change subject: Simplify 5-digit-year regex in DateTimeParser
......................................................................


Simplify 5-digit-year regex in DateTimeParser

The regex was not horrible but can be simpler. This replaces the
"match, split and recombine" approach with a simple "search and
replace".

Change-Id: Ie8e5eba16a1339f9dbef5597c4d065c4cd7c90b7
---
M lib/includes/parsers/DateTimeParser.php
1 file changed, 4 insertions(+), 3 deletions(-)

Approvals:
  Daniel Kinzler: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/lib/includes/parsers/DateTimeParser.php 
b/lib/includes/parsers/DateTimeParser.php
index cd53f9f..05ef0ac 100644
--- a/lib/includes/parsers/DateTimeParser.php
+++ b/lib/includes/parsers/DateTimeParser.php
@@ -71,9 +71,10 @@
 
                        // PHP's DateTime object also can't handle larger than 
4 digit years,
                        // e.g. 1 June 202020
-                       if ( preg_match( '/^(.*\D)?(\d{5,})(.*)$/', $value, 
$matches ) ) {
-                               $value = $matches[1] . substr( $matches[2], -4 
) . $matches[3];
-                               $largeYear = $matches[2];
+                       if ( preg_match( '/\d{5,}/', $value, $matches, 
PREG_OFFSET_CAPTURE ) ) {
+                               $largeYear = $matches[0][0];
+                               // Remove all but the last 4 digits from the 
year found in the string.
+                               $value = substr_replace( $value, '', 
$matches[0][1], strlen( $largeYear ) - 4 );
                        }
 
                        $this->validateDateTimeInput( $value );

-- 
To view, visit https://gerrit.wikimedia.org/r/192295
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: Ie8e5eba16a1339f9dbef5597c4d065c4cd7c90b7
Gerrit-PatchSet: 3
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Thiemo Mättig (WMDE) <[email protected]>
Gerrit-Reviewer: Addshore <[email protected]>
Gerrit-Reviewer: Daniel Kinzler <[email protected]>
Gerrit-Reviewer: Hoo man <[email protected]>
Gerrit-Reviewer: Thiemo Mättig (WMDE) <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to