From 7445f81042f90448b64a6b9c4ac67856078ab4e6 Mon Sep 17 00:00:00 2001 From: Aurimas Vinckevicius Date: Tue, 10 Mar 2015 19:42:22 -0500 Subject: [PATCH] Port Zotero.Date.sqlToISO8601 from 755ead21194f57d11f00e80754d501ac0158bfb6 Copy-pasted, no modifications --- chrome/content/zotero/xpcom/date.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/chrome/content/zotero/xpcom/date.js b/chrome/content/zotero/xpcom/date.js index c92721c9c4..c41b5eec50 100644 --- a/chrome/content/zotero/xpcom/date.js +++ b/chrome/content/zotero/xpcom/date.js @@ -544,6 +544,29 @@ Zotero.Date = new function(){ return false; } + + this.sqlToISO8601 = function (sqlDate) { + var date = sqlDate.substr(0, 10); + var matches = date.match(/^([0-9]{4})\-([0-9]{2})\-([0-9]{2})/); + if (!matches) { + return false; + } + date = matches[1]; + // Drop parts for reduced precision + if (matches[2] !== "00") { + date += "-" + matches[2]; + if (matches[3] !== "00") { + date += "-" + matches[3]; + } + } + var time = sqlDate.substr(11); + // TODO: validate times + if (time) { + date += "T" + time + "Z"; + } + return date; + } + function strToMultipart(str){ if (!str){ return '';