From ca2045a3051e50537ef312ec2e0335786272a607 Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Tue, 13 Jun 2006 15:07:08 +0000 Subject: [PATCH] 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 --- .../content/scholar/xpcom/scholar.js | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/chrome/chromeFiles/content/scholar/xpcom/scholar.js b/chrome/chromeFiles/content/scholar/xpcom/scholar.js index c7b8b9ffea..0a124892cd 100644 --- 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