jenkins-bot has submitted this change and it was merged.
Change subject: Don't use '-' as separator in dates in the time parser
......................................................................
Don't use '-' as separator in dates in the time parser
- added testcases for dates that did not work correctly when replacing
spaces with a '-' in the time parser
Change-Id: I09a632cb745d256ed8ac8c43db3759c9db960576
---
M lib/includes/parsers/DateTimeParser.php
M lib/tests/phpunit/parsers/DateTimeParserTest.php
2 files changed, 8 insertions(+), 3 deletions(-)
Approvals:
WikidataJenkins: Verified
Adrian Lang: Looks good to me, approved
jenkins-bot: Verified
diff --git a/lib/includes/parsers/DateTimeParser.php
b/lib/includes/parsers/DateTimeParser.php
index 04b95a5..0f0643c 100644
--- a/lib/includes/parsers/DateTimeParser.php
+++ b/lib/includes/parsers/DateTimeParser.php
@@ -51,9 +51,10 @@
new ParserOptions()
);
- //WTF PHP FAIL: Apparently PHP doesn't like spaces as
separators in dates, so replace with a '-'
- // See
http://de1.php.net/manual/en/datetime.formats.date.php
- $value = preg_replace( '/\s+/', '-', trim( $value ) );
+ //PHP's DateTime object does not accept spaces as
separators between year, month and day,
+ //e.g. dates like 20 12 2012, but we want to support
them.
+ //See
http://de1.php.net/manual/en/datetime.formats.date.php
+ $value = preg_replace( '/\s+/', '.', trim( $value ) );
//Parse using the DateTime object (this will allow us
to format the date in a nicer way)
//TODO try to match and remove BCE etc. before putting
the value into the DateTime object to get - dates!
diff --git a/lib/tests/phpunit/parsers/DateTimeParserTest.php
b/lib/tests/phpunit/parsers/DateTimeParserTest.php
index b91cf21..67e6503 100644
--- a/lib/tests/phpunit/parsers/DateTimeParserTest.php
+++ b/lib/tests/phpunit/parsers/DateTimeParserTest.php
@@ -67,6 +67,10 @@
array( '+0000000000002009-01-09T00:00:00Z', 0 ,
0 , 0 , TimeValue::PRECISION_DAY , TimeFormatter::CALENDAR_GREGORIAN ),
'2009-01-09' =>
array( '+0000000000002009-01-09T00:00:00Z', 0 ,
0 , 0 , TimeValue::PRECISION_DAY , TimeFormatter::CALENDAR_GREGORIAN ),
+ 'January 9 1920' =>
+ array( '+0000000000001920-01-09T00:00:00Z', 0 ,
0 , 0 , TimeValue::PRECISION_DAY , TimeFormatter::CALENDAR_GREGORIAN ),
+ 'Feb 11 1930' =>
+ array( '+0000000000001930-02-11T00:00:00Z', 0 ,
0 , 0 , TimeValue::PRECISION_DAY , TimeFormatter::CALENDAR_GREGORIAN ),
'1st July 2013' =>
array( '+0000000000002013-07-01T00:00:00Z', 0 ,
0 , 0 , TimeValue::PRECISION_DAY , TimeFormatter::CALENDAR_GREGORIAN ),
'2nd July 2013' =>
--
To view, visit https://gerrit.wikimedia.org/r/118679
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I09a632cb745d256ed8ac8c43db3759c9db960576
Gerrit-PatchSet: 4
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Tobias Gritschacher <[email protected]>
Gerrit-Reviewer: Addshore <[email protected]>
Gerrit-Reviewer: Adrian Lang <[email protected]>
Gerrit-Reviewer: WikidataJenkins <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits