[LON-CAPA-cvs] cvs: loncom /automation batchcreatecourse.pm

raeburn lon-capa-cvs@mail.lon-capa.org
Thu, 11 May 2006 22:41:39 -0000


raeburn		Thu May 11 18:41:39 2006 EDT

  Modified files:              
    /loncom/automation	batchcreatecourse.pm 
  Log:
  Prevent invalid dates from causing batchcreatecourse.pm to stop creating courses. &process_date() now includes code to ensure values passed to timelocal() fall inside valid range.
  
  
Index: loncom/automation/batchcreatecourse.pm
diff -u loncom/automation/batchcreatecourse.pm:1.9 loncom/automation/batchcreatecourse.pm:1.10
--- loncom/automation/batchcreatecourse.pm:1.9	Fri Jan 13 16:36:33 2006
+++ loncom/automation/batchcreatecourse.pm	Thu May 11 18:41:38 2006
@@ -1,5 +1,5 @@
 #
-# $Id: batchcreatecourse.pm,v 1.9 2006/01/13 21:36:33 raeburn Exp $
+# $Id: batchcreatecourse.pm,v 1.10 2006/05/11 22:41:38 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -634,10 +634,45 @@
             if ( length($entries[$j]) > 1 ) {
                 $entries[$j] =~ s/^0//;
             }
+            $entries[$j] =~ s/\D//g;
+            if ($entries[$j] < 0) {
+                $entries[$j] = 0;
+            }
         }
         if ($entries[1] > 0) {  
             $entries[1] = $entries[1] - 1;
         }
+        if ($entries[5] > 60) {
+            $entries[5] = 60;
+        }
+        if ($entries[4] > 59) {
+            $entries[4] = 59;
+        }
+        if ($entries[3] > 23) {
+            $entries[3] = 23;
+        }
+        if ($entries[2] > 31) {
+            $entries[2] = 31;
+        }
+        if ($entries[1] > 11) {
+            $entries[1] = 11;
+        }
+        if ($entries[2] == 31) {
+            if (($entries[1] == 3) || ($entries[1] == 5) ||
+                ($entries[1] == 8) || ($entries[1] == 10)) {
+                $entries[2] = 30;
+            }
+        }
+        if ($entries[1] == 1) {
+            if ($entries[2] > 29) {
+                $entries[2] = 29;
+            }
+            if ($entries[2] == 29) {
+                unless ($entries[0]%4) == 0) {
+                    $entries[2] == 28;
+                }
+            }
+        }     
         $timestamp =  timelocal($entries[5],$entries[4],$entries[3],$entries[2],$entries[1],$entries[0]);
     }
     return $timestamp;