Thiemo Mättig (WMDE) has uploaded a new change for review.
https://gerrit.wikimedia.org/r/304001
Change subject: Rewrite date parser in FormatterHelper
......................................................................
Rewrite date parser in FormatterHelper
Change-Id: I62a44e2cdce2317dd34fc2d47f81372c00991d30
---
M wikibase/queryService/ui/resultBrowser/helper/FormatterHelper.js
1 file changed, 8 insertions(+), 20 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/wikidata/query/gui
refs/changes/01/304001/1
diff --git a/wikibase/queryService/ui/resultBrowser/helper/FormatterHelper.js
b/wikibase/queryService/ui/resultBrowser/helper/FormatterHelper.js
index fe3cccd..9671292 100644
--- a/wikibase/queryService/ui/resultBrowser/helper/FormatterHelper.js
+++ b/wikibase/queryService/ui/resultBrowser/helper/FormatterHelper.js
@@ -147,26 +147,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 );
};
--
To view, visit https://gerrit.wikimedia.org/r/304001
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I62a44e2cdce2317dd34fc2d47f81372c00991d30
Gerrit-PatchSet: 1
Gerrit-Project: wikidata/query/gui
Gerrit-Branch: master
Gerrit-Owner: Thiemo Mättig (WMDE) <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits