From cf8a2c26354f2ced54e446930144416130269c13 Mon Sep 17 00:00:00 2001 From: Aurimas Vinckevicius Date: Sat, 2 Mar 2013 19:08:36 -0600 Subject: [PATCH] Make sure that year is always returned as string --- chrome/content/zotero/xpcom/date.js | 33 ++++++++++++++++------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/chrome/content/zotero/xpcom/date.js b/chrome/content/zotero/xpcom/date.js index c6be728e6..edca6e8cd 100644 --- a/chrome/content/zotero/xpcom/date.js +++ b/chrome/content/zotero/xpcom/date.js @@ -228,18 +228,6 @@ Zotero.Date = new function(){ var _dayRe = null; function strToDate(string) { - // Parse 'yesterday'/'today'/'tomorrow' - var lc = (string + '').toLowerCase(); - if (lc == 'yesterday' || (Zotero.getString && lc === Zotero.getString('date.yesterday'))) { - string = Zotero.Date.dateToSQL(new Date(new Date().getTime() - 86400000)).substr(0, 10); - } - else if (lc == 'today' || (Zotero.getString && lc == Zotero.getString('date.today'))) { - string = Zotero.Date.dateToSQL(new Date()).substr(0, 10); - } - else if (lc == 'tomorrow' || (Zotero.getString && lc == Zotero.getString('date.tomorrow'))) { - string = Zotero.Date.dateToSQL(new Date(new Date().getTime() + 86400000)).substr(0, 10); - } - var date = new Object(); // skip empty things @@ -247,7 +235,19 @@ Zotero.Date = new function(){ return date; } - string = string.toString().replace(/^\s+/, "").replace(/\s+$/, "").replace(/\s+/, " "); + // Parse 'yesterday'/'today'/'tomorrow' + var lc = (string + '').toLowerCase(); + if (lc == 'yesterday' || (Zotero.getString && lc === Zotero.getString('date.yesterday'))) { + string = Zotero.Date.dateToSQL(new Date(Date.now() - 1000*60*60*24)).substr(0, 10); + } + else if (lc == 'today' || (Zotero.getString && lc == Zotero.getString('date.today'))) { + string = Zotero.Date.dateToSQL(new Date()).substr(0, 10); + } + else if (lc == 'tomorrow' || (Zotero.getString && lc == Zotero.getString('date.tomorrow'))) { + 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+/, " "); + } // first, directly inspect the string var m = _slashRe.exec(string); @@ -390,13 +390,16 @@ Zotero.Date = new function(){ // clean up date part if(date.part) { - date.part = date.part.replace(/^[^A-Za-z0-9]+/, "").replace(/[^A-Za-z0-9]+$/, ""); + date.part = date.part.replace(/^[^A-Za-z0-9]+|[^A-Za-z0-9]+$/g, ""); } if(date.part === "" || date.part == undefined) { delete date.part; } + //make sure year is always a string + if(date.year || date.year === 0) date.year += ''; + return date; } @@ -705,4 +708,4 @@ Zotero.Date = new function(){ } return _localeDateOrder; } -} \ No newline at end of file +}