www

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

commit ca2045a3051e50537ef312ec2e0335786272a607
parent 39f9d2c3b38c8a9d09d890927a0b0ff7c2f53a33
Author: Dan Stillman <dstillman@zotero.org>
Date:   Tue, 13 Jun 2006 15:07:08 +0000

Scholar.Date.sqlToDate(string sqldate) -- function to convert SQL-formatted date (e.g. '2006-06-13 11:03:05' or '2006-06-13') into a JS date object


Diffstat:
Mchrome/chromeFiles/content/scholar/xpcom/scholar.js | 30++++++++++++++++++++++++++++++
1 file changed, 30 insertions(+), 0 deletions(-)

diff --git a/chrome/chromeFiles/content/scholar/xpcom/scholar.js b/chrome/chromeFiles/content/scholar/xpcom/scholar.js @@ -384,4 +384,34 @@ Scholar.HTTP = new function(){ break; } } +} + + + +Scholar.Date = new function(){ + this.sqlToDate = sqlToDate; + + /** + * Convert an SQL date in the form '2006-06-13 11:03:05' into a JS Date object + * + * Can also accept just the date part (e.g. '2006-06-13') + **/ + function sqlToDate(sqldate){ + try { + var datetime = sqldate.split(' '); + var dateparts = datetime[0].split('-'); + if (datetime[1]){ + var timeparts = datetime[1].split(':'); + } + else { + timeparts = [false, false, false]; + } + return new Date(dateparts[0], dateparts[1], dateparts[2], + timeparts[0], timeparts[1], timeparts[2]); + } + catch (e){ + Scholar.debug(sqldate + ' is not a valid SQL date', 2) + return false; + } + } } \ No newline at end of file