Mvolz has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/353706 )

Change subject: If only year is provided, only put year in date field
......................................................................

If only year is provided, only put year in date field

Temporary measure to deal with dates where the month
and day are ambiguous.

Bug: T132308
Change-Id: I8e845d8bd0c97522e983c046bafb2ffb558e87ae
---
M lib/Exporter.js
M test/features/unit/exporter.js
2 files changed, 10 insertions(+), 8 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/services/citoid 
refs/changes/06/353706/1

diff --git a/lib/Exporter.js b/lib/Exporter.js
index 6717a51..4f7e573 100644
--- a/lib/Exporter.js
+++ b/lib/Exporter.js
@@ -542,11 +542,13 @@
     if (citation.date){
         try {
             var d;
-            // Strip copyright symbol if date is in format c2009 or ©2009; 
common in Worldcat
-            var matched = citation.date.trim().match(/^(?:c|©)(\d{4})$/);
+            // Strip copyright symbol if date is in format c2009 or ©2009 
(common in Worldcat); also match year only
+            var matched = citation.date.trim().match(/^(?:c|©)?(\d{4})$/);
             if (matched){
                 citation.date = matched[1]; // Use second group; 0 index group 
is full match
+                return citation; // Return year if that's all that's available
             }
+
             // Try to parse with chrono first
             var p = customChrono.parse(citation.date); // Create ParsedResult 
object with chrono
             if (p && p[0] && p[0].start){
diff --git a/test/features/unit/exporter.js b/test/features/unit/exporter.js
index 87ba215..f6bb020 100644
--- a/test/features/unit/exporter.js
+++ b/test/features/unit/exporter.js
@@ -49,28 +49,28 @@
 
         it('Contains copyright symbol', function() {
             date = '©2010';
-            expected = {date: '2010-01-01'};
+            expected = {date: '2010'};
             result = exporter.fixDate({date:date});
             assert.deepEqual(result, expected);
         });
 
         it('Contains copyright symbol & whitespace', function() {
             date = ' ©2010';
-            expected = {date: '2010-01-01'};
+            expected = {date: '2010'};
             result = exporter.fixDate({date:date});
             assert.deepEqual(result, expected);
         });
 
         it('Contains c symbol', function() {
             date = 'c2010';
-            expected = {date: '2010-01-01'};
+            expected = {date: '2010'};
             result = exporter.fixDate({date:date});
             assert.deepEqual(result, expected);
         });
 
-        it('sets year only date to January 1st of that year', function() {
+        it('sets year only date to year only date', function() {
             date = '2010';
-            expected = {date: '2010-01-01'};
+            expected = {date: '2010'};
             result = exporter.fixDate({date:date});
             assert.deepEqual(result, expected);
         });
@@ -82,7 +82,7 @@
             assert.deepEqual(result, expected);
         });
 
-        it('Uses year from ambiguous date', function() {
+        it('Uses year from ambiguous date', function() { // Partial ISO?
             date = 'Fall 1975';
             expected = {date: '1975-01-01'};
             result = exporter.fixDate({date:date});

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I8e845d8bd0c97522e983c046bafb2ffb558e87ae
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/services/citoid
Gerrit-Branch: master
Gerrit-Owner: Mvolz <mv...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to