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

Change subject: Rewrite date parser in FormatterHelper
......................................................................


Rewrite date parser in FormatterHelper

Change-Id: I62a44e2cdce2317dd34fc2d47f81372c00991d30
---
M wikibase/queryService/ui/resultBrowser/helper/FormatterHelper.js
M wikibase/tests/queryService/ui/resultBrowser/helper/FormatterHelper.test.js
2 files changed, 12 insertions(+), 20 deletions(-)

Approvals:
  Jonas Kress (WMDE): Looks good to me, approved
  jenkins-bot: Verified



diff --git a/wikibase/queryService/ui/resultBrowser/helper/FormatterHelper.js 
b/wikibase/queryService/ui/resultBrowser/helper/FormatterHelper.js
index 6d1ac97..9ccf2cc 100644
--- a/wikibase/queryService/ui/resultBrowser/helper/FormatterHelper.js
+++ b/wikibase/queryService/ui/resultBrowser/helper/FormatterHelper.js
@@ -164,26 +164,14 @@
         * @return {Object}
         */
        SELF.prototype.parseDate = function( dateTime ) {
-
-               if ( !dateTime.startsWith( '+' ) && !dateTime.startsWith( '-' ) 
) {
-                       dateTime = '+' + dateTime;
-               }
-
-               //Add leading zeros to positve year
-               dateTime = dateTime.replace( /^\+(\d{1})-/, '+00000$1-' )
-               .replace( /^\+(\d{2})-/, '+0000$1-' )
-               .replace( /^\+(\d{3})-/, '+000$1-' )
-               .replace( /^\+(\d{4})-/, '+00$1-' )
-               .replace( /^\+(\d{5})-/, '+0$1-' );
-
-               //Add leading zeros to negative year
-               dateTime = dateTime.replace( /^-(\d{1})-/, '-00000$1-' )
-               .replace( /^-(\d{2})-/, '-0000$1-' )
-               .replace( /^-(\d{3})-/, '-000$1-' )
-               .replace( /^-(\d{4})-/, '-00$1-' )
-               .replace( /^-(\d{5})-/, '-0$1-' );
-
-               dateTime = dateTime.replace( 'Z', '' );//remove timezone
+               // Add leading plus sign if it's missing
+               dateTime = dateTime.replace( /^(?![+-])/, '+' );
+               // Pad years to 6 digits
+               dateTime = dateTime.replace( /^([+-]?)(\d{1,5}\b)/, function( 
$0, $1, $2 ) {
+                       return $1 + ( '00000' + $2 ).slice( -6 );
+               } );
+               // Remove timezone
+               dateTime = dateTime.replace( /Z$/, '' );
 
                return moment( dateTime, moment.ISO_8601 );
        };
diff --git 
a/wikibase/tests/queryService/ui/resultBrowser/helper/FormatterHelper.test.js 
b/wikibase/tests/queryService/ui/resultBrowser/helper/FormatterHelper.test.js
index 0e83159..e64dcf9 100644
--- 
a/wikibase/tests/queryService/ui/resultBrowser/helper/FormatterHelper.test.js
+++ 
b/wikibase/tests/queryService/ui/resultBrowser/helper/FormatterHelper.test.js
@@ -13,6 +13,10 @@
 
        QUnit.test( 'parseDate', function( assert ) {
                var testCases = [
+                       [ '2016-12-31', '2016-12-31' ],
+                       [ '2016-12-31T00:00:00', '2016-12-31' ],
+
+                       // Testing the supported range
                        [ '-1000000-12-31T00:00:00Z', 'Invalid date' ],
                        [ '-271821-01-01T00:00:00Z', 'Invalid date' ],
                        [ '-271820-01-01T00:00:00Z', '-271820-01-01' ],

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I62a44e2cdce2317dd34fc2d47f81372c00991d30
Gerrit-PatchSet: 3
Gerrit-Project: wikidata/query/gui
Gerrit-Branch: master
Gerrit-Owner: Thiemo Mättig (WMDE) <[email protected]>
Gerrit-Reviewer: Jonas Kress (WMDE) <[email protected]>
Gerrit-Reviewer: Smalyshev <[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