From 69f273a60ecad5799df720e77c399f9c6603d456 Mon Sep 17 00:00:00 2001 From: Simon Kornblith Date: Fri, 15 Jun 2012 15:54:27 -0400 Subject: [PATCH] Fix handling of item types and accesDate in ZU.itemFromCSLJSON() --- chrome/content/zotero/xpcom/utilities.js | 27 +++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/chrome/content/zotero/xpcom/utilities.js b/chrome/content/zotero/xpcom/utilities.js index 9088a934f4..88bcb55bef 100644 --- a/chrome/content/zotero/xpcom/utilities.js +++ b/chrome/content/zotero/xpcom/utilities.js @@ -1399,7 +1399,7 @@ Zotero.Utilities = { var isZoteroItem = item instanceof Zotero.Item, zoteroType; for(var type in CSL_TYPE_MAPPINGS) { - if(CSL_TYPE_MAPPINGS[zoteroType] == item.type) { + if(CSL_TYPE_MAPPINGS[type] == cslItem.type) { zoteroType = type; break; } @@ -1484,11 +1484,28 @@ Zotero.Utilities = { if(Zotero.ItemFields.isValidForType(fieldID, itemTypeID)) { var date = ""; if(cslDate.literal) { - date = cslDate.literal; + if(variable === "accessed") { + date = strToISO(cslDate.literal); + } else { + date = cslDate.literal; + } } else if(cslDate.year) { - if(cslDate.month) cslDate.month--; - date = Zotero.Date.formatDate(cslDate); - if(cslDate.season) date = cslDate.season+date; + if(variable === "accessed") { + // Need to convert to SQL + var date = Zotero.Utilities.lpad(cslDate.year, "0", 4); + if(cslDate.month) { + date += "-"+Zotero.Utilities.lpad(cslDate.month+1, "0", 2); + if(cslDate.day) { + date += "-"+Zotero.Utilities.lpad(cslDate.day, "0", 2); + } + } + } else { + if(cslDate.month) cslDate.month--; + date = Zotero.Date.formatDate(cslDate); + if(cslDate.season) { + date = date+" "+cslDate.season; + } + } } if(isZoteroItem) {