www

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

commit a017fe6666eb870b622424731a98a2c13da462b5
parent b00d1366b00fecc4d656017b72b7e7011f152084
Author: Dan Stillman <dstillman@zotero.org>
Date:   Tue, 17 Jan 2017 02:23:15 -0500

Fix Zotero.Date methods within translator sandbox

Only a few methods are imported, so some of the changes in 7bdcc17ed
have to be reverted.

Diffstat:
Mchrome/content/zotero/xpcom/date.js | 12++++++------
Mtest/tests/dateTest.js | 20++++++++++++++++++++
2 files changed, 26 insertions(+), 6 deletions(-)

diff --git a/chrome/content/zotero/xpcom/date.js b/chrome/content/zotero/xpcom/date.js @@ -260,7 +260,7 @@ Zotero.Date = new function(){ this.isoToSQL = function (isoDate) { - return this.dateToSQL(this.isoToDate(isoDate), true); + return Zotero.Date.dateToSQL(Zotero.Date.isoToDate(isoDate), true); // no 'this' for translator sandbox } @@ -294,13 +294,13 @@ Zotero.Date = new function(){ // Parse 'yesterday'/'today'/'tomorrow' var lc = (string + '').toLowerCase(); if (lc == 'yesterday' || (Zotero.getString && lc === Zotero.getString('date.yesterday'))) { - string = this.dateToSQL(new Date(Date.now() - 1000*60*60*24)).substr(0, 10); + string = Zotero.Date.dateToSQL(new Date(Date.now() - 1000*60*60*24)).substr(0, 10); // no 'this' for translator sandbox } else if (lc == 'today' || (Zotero.getString && lc == Zotero.getString('date.today'))) { - string = this.dateToSQL(new Date()).substr(0, 10); + string = Zotero.Date.dateToSQL(new Date()).substr(0, 10); } else if (lc == 'tomorrow' || (Zotero.getString && lc == Zotero.getString('date.tomorrow'))) { - string = this.dateToSQL(new Date(Date.now() + 1000*60*60*24)).substr(0, 10); + string = Zotero.Date.dateToSQL(new Date(Date.now() + 1000*60*60*24)).substr(0, 10); } else { string = string.toString().replace(/^\s+|\s+$/g, "").replace(/\s+/, " "); @@ -425,7 +425,7 @@ Zotero.Date = new function(){ // MONTH if(date.month === undefined) { // compile month regular expression - let months = this.getMonths(true); + let months = Zotero.Date.getMonths(true); // no 'this' for translator sandbox months = months.short.map(m => m.toLowerCase()) .concat(months.long.map(m => m.toLowerCase())); @@ -601,7 +601,7 @@ Zotero.Date = new function(){ string += date.part+" "; } - var months = this.getMonths().long; + var months = Zotero.Date.getMonths().long; // no 'this' for translator sandbox if(date.month != undefined && months[date.month]) { // get short month strings from CSL interpreter string += months[date.month]; diff --git a/test/tests/dateTest.js b/test/tests/dateTest.js @@ -156,6 +156,26 @@ describe("Zotero.Date", function() { }) }) + describe("#strToDate()", function () { + it("should work in translator sandbox", function* () { + var item = createUnsavedDataObject('item'); + item.libraryID = Zotero.Libraries.userLibraryID; + item.setField('date', '2017-01-17'); + + var called = false; + var translation = new Zotero.Translate.Export(); + translation.setItems([item]); + translation.setTranslator("9cb70025-a888-4a29-a210-93ec52da40d4"); // BibTeX + translation.setHandler("done", function (obj, worked) { + called = true; + assert.isTrue(worked); + assert.include(obj.string, "{2017}"); + }); + yield translation.translate(); + assert.ok(called); + }); + }); + describe("#isHTTPDate()", function() { it("should determine whether a date is an RFC 2822 compliant date", function() { assert.ok(Zotero.Date.isHTTPDate("Mon, 13 Jun 2016 02:09:08 +4000"));