Fix "value is undefined" error handling dates from embedded data

This commit is contained in:
Simon Kornblith 2012-06-17 10:12:40 -04:00
parent 69f273a60e
commit 698254adb7

View File

@ -1489,21 +1489,30 @@ Zotero.Utilities = {
} else { } else {
date = cslDate.literal; date = cslDate.literal;
} }
} else if(cslDate.year) { } else {
var newDate = Zotero.Utilities.deepCopy(cslDate);;
if(cslDate.dateParts && typeof cslDate.dateParts == "object") {
if(cslDate.dateParts[0]) newDate.year = cslDate.dateParts[0];
if(cslDate.dateParts[1]) newDate.month = cslDate.dateParts[1];
if(cslDate.dateParts[2]) newDate.day = cslDate.dateParts[2];
}
if(newDate.year) {
if(variable === "accessed") { if(variable === "accessed") {
// Need to convert to SQL // Need to convert to SQL
var date = Zotero.Utilities.lpad(cslDate.year, "0", 4); var date = Zotero.Utilities.lpad(newDate.year, "0", 4);
if(cslDate.month) { if(newDate.month) {
date += "-"+Zotero.Utilities.lpad(cslDate.month+1, "0", 2); date += "-"+Zotero.Utilities.lpad(newDate.month+1, "0", 2);
if(cslDate.day) { if(newDate.day) {
date += "-"+Zotero.Utilities.lpad(cslDate.day, "0", 2); date += "-"+Zotero.Utilities.lpad(newDate.day, "0", 2);
} }
} }
} else { } else {
if(cslDate.month) cslDate.month--; if(newDate.month) newDate.month--;
date = Zotero.Date.formatDate(cslDate); date = Zotero.Date.formatDate(newDate);
if(cslDate.season) { if(newDate.season) {
date = date+" "+cslDate.season; date = newDate.season+" "+date;
}
} }
} }
} }