added method to build a date and return null if the date is invalid from a human...
authorerickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Mon, 24 Jul 2006 20:25:49 +0000 (20:25 +0000)
committererickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Mon, 24 Jul 2006 20:25:49 +0000 (20:25 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/trunk@5103 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/web/opac/common/js/utils.js

index bd27682..62c9f5d 100644 (file)
@@ -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;
+}
+
+