www

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | Submodules | README | LICENSE

commit 70f021f945cb686fc3898facab63c502cf528b08
parent 8448203583ff12af2219a673942a5aec2e8b08ff
Author: Simon Kornblith <simon@simonster.com>
Date:   Sun,  7 Jun 2015 18:38:00 -0400

Use ISO 8601 accessDates everywhere

This uses ISO 8601 dates for generateAllTypesAndFieldsData (and
changes populateDBWithSampleData to use Item#fromJSON), and makes
translators expect ISO 8601 accessDates, although SQL accessDates are
still supported with a deprecation warning. Canonicalization happens in
Zotero.Translate, so I need to remember to update connectors as well.

Diffstat:
Mchrome/content/zotero/xpcom/translation/translate.js | 16++++++++++++++--
Mchrome/content/zotero/xpcom/translation/translate_item.js | 1-
Mtest/content/support.js | 27+++------------------------
Mtest/tests/data/allTypesAndFields.js | 68++++++++++++++++++++++++++++++++++----------------------------------
Mtest/tests/data/journalArticle.js | 2+-
Mtest/tests/supportTest.js | 4+++-
Mtest/tests/translateTest.js | 23+++++++++++++++++++++++
7 files changed, 78 insertions(+), 63 deletions(-)

diff --git a/chrome/content/zotero/xpcom/translation/translate.js b/chrome/content/zotero/xpcom/translation/translate.js @@ -174,6 +174,18 @@ Zotero.Translate.Sandbox = { } } } + + if (item.version) { + translate._debug("Translate: item.version is deprecated; set item.versionNumber instead"); + item.versionNumber = item.version; + } + + if (item.accessDate) { + if (Zotero.Date.isSQLDateTime(item.accessDate)) { + translate._debug("Translate: Passing accessDate as SQL is deprecated; pass an ISO 8601 date instead"); + item.accessDate = Zotero.Date.sqlToISO8601(item.accessDate); + } + } // Fire itemSaving event translate._runHandler("itemSaving", item); @@ -581,13 +593,13 @@ Zotero.Translate.Sandbox = { } // automatically set library catalog - if(item.libraryCatalog === undefined) { + if(item.libraryCatalog === undefined && item.itemType != "webpage") { item.libraryCatalog = translate.translator[0].label; } // automatically set access date if URL is set if(item.url && typeof item.accessDate == 'undefined') { - item.accessDate = "CURRENT_TIMESTAMP"; + item.accessDate = Zotero.Date.dateToISO(new Date()); } //consider type-specific "title" alternatives diff --git a/chrome/content/zotero/xpcom/translation/translate_item.js b/chrome/content/zotero/xpcom/translation/translate_item.js @@ -107,7 +107,6 @@ Zotero.Translate.ItemSaver.prototype = { seeAlso:item.seeAlso, id:item.itemID || item.id }; - if (item.version) item.versionNumber = item.version; newItem.fromJSON(this._deleteIrrelevantFields(item)); // save item diff --git a/test/content/support.js b/test/content/support.js @@ -411,7 +411,7 @@ function generateAllTypesAndFieldsData() { let specialValues = { date: '1999-12-31', filingDate: '2000-01-02', - accessDate: '1997-06-13 23:59:58', + accessDate: '1997-06-13T23:59:58', number: 3, numPages: 4, issue: 5, @@ -482,29 +482,8 @@ function populateDBWithSampleData(data) { return Zotero.DB.executeTransaction(function* () { for (let itemName in data) { let item = data[itemName]; - let zItem = new Zotero.Item(item.itemType); - for (let itemField in item) { - if (itemField == 'itemType') continue; - - if (itemField == 'creators') { - zItem.setCreators(item[itemField]); - continue; - } - - if (itemField == 'tags') { - // Must save item first - continue; - } - - zItem.setField(itemField, item[itemField]); - } - - if (item.tags && item.tags.length) { - for (let i=0; i<item.tags.length; i++) { - zItem.addTag(item.tags[i].tag, item.tags[i].type); - } - } - + let zItem = new Zotero.Item; + zItem.fromJSON(item); item.id = yield zItem.save(); } diff --git a/test/tests/data/allTypesAndFields.js b/test/tests/data/allTypesAndFields.js @@ -1,7 +1,7 @@ { "artwork": { "abstractNote": "Abstract note", - "accessDate": "1997-06-13 23:59:58", + "accessDate": "1997-06-13T23:59:58", "archive": "Archive", "archiveLocation": "Archive location", "artworkSize": "Artwork size", @@ -32,7 +32,7 @@ "audioRecording": { "ISBN": "978-1-234-56789-7", "abstractNote": "Abstract note", - "accessDate": "1997-06-13 23:59:58", + "accessDate": "1997-06-13T23:59:58", "archive": "Archive", "archiveLocation": "Archive location", "callNumber": "Call number", @@ -77,7 +77,7 @@ }, "bill": { "abstractNote": "Abstract note", - "accessDate": "1997-06-13 23:59:58", + "accessDate": "1997-06-13T23:59:58", "code": "Code", "creators": [ { @@ -114,7 +114,7 @@ }, "blogPost": { "abstractNote": "Abstract note", - "accessDate": "1997-06-13 23:59:58", + "accessDate": "1997-06-13T23:59:58", "creators": [ { "creatorType": "author", @@ -146,7 +146,7 @@ "book": { "ISBN": "978-1-234-56789-7", "abstractNote": "Abstract note", - "accessDate": "1997-06-13 23:59:58", + "accessDate": "1997-06-13T23:59:58", "archive": "Archive", "archiveLocation": "Archive location", "callNumber": "Call number", @@ -198,7 +198,7 @@ "bookSection": { "ISBN": "978-1-234-56789-7", "abstractNote": "Abstract note", - "accessDate": "1997-06-13 23:59:58", + "accessDate": "1997-06-13T23:59:58", "archive": "Archive", "archiveLocation": "Archive location", "callNumber": "Call number", @@ -255,7 +255,7 @@ }, "case": { "abstractNote": "Abstract note", - "accessDate": "1997-06-13 23:59:58", + "accessDate": "1997-06-13T23:59:58", "court": "Court", "creators": [ { @@ -291,7 +291,7 @@ "computerProgram": { "ISBN": "978-1-234-56789-7", "abstractNote": "Abstract note", - "accessDate": "1997-06-13 23:59:58", + "accessDate": "1997-06-13T23:59:58", "archive": "Archive", "archiveLocation": "Archive location", "callNumber": "Call number", @@ -326,7 +326,7 @@ "DOI": "10.1234/example.doi", "ISBN": "978-1-234-56789-7", "abstractNote": "Abstract note", - "accessDate": "1997-06-13 23:59:58", + "accessDate": "1997-06-13T23:59:58", "archive": "Archive", "archiveLocation": "Archive location", "callNumber": "Call number", @@ -377,7 +377,7 @@ "dictionaryEntry": { "ISBN": "978-1-234-56789-7", "abstractNote": "Abstract note", - "accessDate": "1997-06-13 23:59:58", + "accessDate": "1997-06-13T23:59:58", "archive": "Archive", "archiveLocation": "Archive location", "callNumber": "Call number", @@ -429,7 +429,7 @@ }, "document": { "abstractNote": "Abstract note", - "accessDate": "1997-06-13 23:59:58", + "accessDate": "1997-06-13T23:59:58", "archive": "Archive", "archiveLocation": "Archive location", "callNumber": "Call number", @@ -473,7 +473,7 @@ }, "email": { "abstractNote": "Abstract note", - "accessDate": "1997-06-13 23:59:58", + "accessDate": "1997-06-13T23:59:58", "creators": [ { "creatorType": "author", @@ -503,7 +503,7 @@ "encyclopediaArticle": { "ISBN": "978-1-234-56789-7", "abstractNote": "Abstract note", - "accessDate": "1997-06-13 23:59:58", + "accessDate": "1997-06-13T23:59:58", "archive": "Archive", "archiveLocation": "Archive location", "callNumber": "Call number", @@ -555,7 +555,7 @@ }, "film": { "abstractNote": "Abstract note", - "accessDate": "1997-06-13 23:59:58", + "accessDate": "1997-06-13T23:59:58", "archive": "Archive", "archiveLocation": "Archive location", "callNumber": "Call number", @@ -597,7 +597,7 @@ }, "forumPost": { "abstractNote": "Abstract note", - "accessDate": "1997-06-13 23:59:58", + "accessDate": "1997-06-13T23:59:58", "creators": [ { "creatorType": "author", @@ -623,7 +623,7 @@ }, "hearing": { "abstractNote": "Abstract note", - "accessDate": "1997-06-13 23:59:58", + "accessDate": "1997-06-13T23:59:58", "committee": "Committee", "creators": [ { @@ -651,7 +651,7 @@ }, "instantMessage": { "abstractNote": "Abstract note", - "accessDate": "1997-06-13 23:59:58", + "accessDate": "1997-06-13T23:59:58", "creators": [ { "creatorType": "author", @@ -680,7 +680,7 @@ }, "interview": { "abstractNote": "Abstract note", - "accessDate": "1997-06-13 23:59:58", + "accessDate": "1997-06-13T23:59:58", "archive": "Archive", "archiveLocation": "Archive location", "callNumber": "Call number", @@ -721,7 +721,7 @@ "DOI": "10.1234/example.doi", "ISSN": "1234-5679", "abstractNote": "Abstract note", - "accessDate": "1997-06-13 23:59:58", + "accessDate": "1997-06-13T23:59:58", "archive": "Archive", "archiveLocation": "Archive location", "callNumber": "Call number", @@ -772,7 +772,7 @@ }, "letter": { "abstractNote": "Abstract note", - "accessDate": "1997-06-13 23:59:58", + "accessDate": "1997-06-13T23:59:58", "archive": "Archive", "archiveLocation": "Archive location", "callNumber": "Call number", @@ -807,7 +807,7 @@ "magazineArticle": { "ISSN": "1234-5679", "abstractNote": "Abstract note", - "accessDate": "1997-06-13 23:59:58", + "accessDate": "1997-06-13T23:59:58", "archive": "Archive", "archiveLocation": "Archive location", "callNumber": "Call number", @@ -849,7 +849,7 @@ }, "manuscript": { "abstractNote": "Abstract note", - "accessDate": "1997-06-13 23:59:58", + "accessDate": "1997-06-13T23:59:58", "archive": "Archive", "archiveLocation": "Archive location", "callNumber": "Call number", @@ -886,7 +886,7 @@ "map": { "ISBN": "978-1-234-56789-7", "abstractNote": "Abstract note", - "accessDate": "1997-06-13 23:59:58", + "accessDate": "1997-06-13T23:59:58", "archive": "Archive", "archiveLocation": "Archive location", "callNumber": "Call number", @@ -926,7 +926,7 @@ "newspaperArticle": { "ISSN": "1234-5679", "abstractNote": "Abstract note", - "accessDate": "1997-06-13 23:59:58", + "accessDate": "1997-06-13T23:59:58", "archive": "Archive", "archiveLocation": "Archive location", "callNumber": "Call number", @@ -969,7 +969,7 @@ }, "patent": { "abstractNote": "Abstract note", - "accessDate": "1997-06-13 23:59:58", + "accessDate": "1997-06-13T23:59:58", "applicationNumber": "Application number", "assignee": "Assignee", "country": "Country", @@ -1009,7 +1009,7 @@ }, "podcast": { "abstractNote": "Abstract note", - "accessDate": "1997-06-13 23:59:58", + "accessDate": "1997-06-13T23:59:58", "creators": [ { "creatorType": "podcaster", @@ -1041,7 +1041,7 @@ }, "presentation": { "abstractNote": "Abstract note", - "accessDate": "1997-06-13 23:59:58", + "accessDate": "1997-06-13T23:59:58", "creators": [ { "creatorType": "presenter", @@ -1068,7 +1068,7 @@ }, "radioBroadcast": { "abstractNote": "Abstract note", - "accessDate": "1997-06-13 23:59:58", + "accessDate": "1997-06-13T23:59:58", "archive": "Archive", "archiveLocation": "Archive location", "callNumber": "Call number", @@ -1122,7 +1122,7 @@ }, "report": { "abstractNote": "Abstract note", - "accessDate": "1997-06-13 23:59:58", + "accessDate": "1997-06-13T23:59:58", "archive": "Archive", "archiveLocation": "Archive location", "callNumber": "Call number", @@ -1166,7 +1166,7 @@ }, "statute": { "abstractNote": "Abstract note", - "accessDate": "1997-06-13 23:59:58", + "accessDate": "1997-06-13T23:59:58", "code": "Code", "codeNumber": "Code number", "creators": [ @@ -1197,7 +1197,7 @@ }, "thesis": { "abstractNote": "Abstract note", - "accessDate": "1997-06-13 23:59:58", + "accessDate": "1997-06-13T23:59:58", "archive": "Archive", "archiveLocation": "Archive location", "callNumber": "Call number", @@ -1229,7 +1229,7 @@ }, "tvBroadcast": { "abstractNote": "Abstract note", - "accessDate": "1997-06-13 23:59:58", + "accessDate": "1997-06-13T23:59:58", "archive": "Archive", "archiveLocation": "Archive location", "callNumber": "Call number", @@ -1284,7 +1284,7 @@ "videoRecording": { "ISBN": "978-1-234-56789-7", "abstractNote": "Abstract note", - "accessDate": "1997-06-13 23:59:58", + "accessDate": "1997-06-13T23:59:58", "archive": "Archive", "archiveLocation": "Archive location", "callNumber": "Call number", @@ -1334,7 +1334,7 @@ }, "webpage": { "abstractNote": "Abstract note", - "accessDate": "1997-06-13 23:59:58", + "accessDate": "1997-06-13T23:59:58", "creators": [ { "creatorType": "author", diff --git a/test/tests/data/journalArticle.js b/test/tests/data/journalArticle.js @@ -3,7 +3,7 @@ "DOI": "10.1234/example.doi", "ISSN": "1234-5679", "abstractNote": "Abstract note", - "accessDate": "1997-06-13 23:59:58", + "accessDate": "1997-06-13T23:59:58Z", "archive": "Archive", "archiveLocation": "Archive location", "callNumber": "Call number", diff --git a/test/tests/supportTest.js b/test/tests/supportTest.js @@ -41,7 +41,9 @@ describe("Support Functions for Unit Testing", function() { if (skipFields.indexOf(prop) != -1) continue; // Using base-mapped fields - assert.equal(item[prop], zItem.getField(prop, false, true), 'inserted item property has the same value as sample data'); + let field = zItem.getField(prop, false, true); + if (prop === "accessDate") field = Zotero.Date.sqlToISO8601(field); + assert.equal(field, item[prop], 'inserted item property has the same value as sample data'); } if (item.creators) { diff --git a/test/tests/translateTest.js b/test/tests/translateTest.js @@ -183,6 +183,16 @@ describe("Zotero.Translate", function() { assert.deepEqual(savedItems, trueItems, "saved items match inputs"); }); + it('should accept deprecated SQL accessDates', function* () { + let myItem = { + "itemType":"webpage", + "title":"Test Item", + "accessDate":"2015-01-02 03:04:05" + } + let newItems = yield saveItemsThroughTranslator("import", [myItem]); + assert.equal(newItems[0].getField("accessDate"), "2015-01-02 03:04:05"); + }); + it('should save tags', function* () { let myItem = { "itemType":"book", @@ -392,6 +402,19 @@ describe("Zotero.Translate", function() { assert.equal(newItems[0].getAttachments().length, 0); }); + it('web translators should set accessDate to current date', function* () { + let myItem = { + "itemType":"webpage", + "title":"Test Item", + "url":"http://www.zotero.org/" + }; + let newItems = yield saveItemsThroughTranslator("web", [myItem]); + let currentDate = new Date(); + let delta = currentDate - Zotero.Date.sqlToDate(newItems[0].getField("accessDate"), true); + assert.isAbove(delta, -500); + assert.isBelow(delta, 5000); + }); + it('web translators should save attachments', function* () { let myItems = [ {