From 86c47d4885225040d1f51ca1bac9ed364f45d01b Mon Sep 17 00:00:00 2001 From: erickson Date: Mon, 24 Jul 2006 20:25:49 +0000 Subject: [PATCH] added method to build a date and return null if the date is invalid from a human perspective git-svn-id: svn://svn.open-ils.org/ILS/trunk@5103 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- Open-ILS/web/opac/common/js/utils.js | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/Open-ILS/web/opac/common/js/utils.js b/Open-ILS/web/opac/common/js/utils.js index bd27682da9..62c9f5d75c 100644 --- a/Open-ILS/web/opac/common/js/utils.js +++ b/Open-ILS/web/opac/common/js/utils.js @@ -572,3 +572,36 @@ function contains(arr, item) { function isTrue(i) { return (i && !(i+'').match(/f/i) ); } + + +/* builds a JS date object with the given info. The given data + has to be valid (e.g. months == 30 is not valid). Returns NULL on + invalid date + Months are 1-12 (unlike the JS date object) + */ + +function buildDate( year, month, day, hours, minutes, seconds ) { + + if(!year) year = 0; + if(!month) month = 1; + if(!day) day = 1; + if(!hours) hours = 0; + if(!minutes) minutes = 0; + if(!seconds) seconds = 0; + + var d = new Date(year, month - 1, day, hours, minutes, seconds); + + if( + (d.getYear() + 1900) == year && + d.getMonth() == (month - 1) && + d.getDate() == parseInt(day) && + d.getHours() == parseInt(hours) && + d.getMinutes() == parseInt(minutes) && + d.getSeconds() == parseInt(seconds) ) { + return d; + } + + return null; +} + + -- 2.11.0