]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-11538: lib/olson - bugfix, olson time-zone import doesn't deal with rule changes...
authormattc-catalyst <mattc-catalyst>
Tue, 2 Oct 2007 01:43:07 +0000 (01:43 +0000)
committermattc-catalyst <mattc-catalyst>
Tue, 2 Oct 2007 01:43:07 +0000 (01:43 +0000)
Author: Matt Clarkson <mattc@catalyst.net.nz>

lib/olson.php

index ac8349236337001c6db042fef579f8f872f4809d..9b185e824916ba9732045643f08ce01e7a4529c3 100644 (file)
@@ -199,6 +199,38 @@ function olson_simple_rule_parser ($filename) {
         return false;
     }
     
+    // determine the maximum year for this zone
+    $maxyear = array();
+    
+    while ($line = fgets($file)) {
+        // only pay attention to rules lines
+        if(!preg_match('/^Rule\s/', $line)){
+            continue;
+        }
+        $line = preg_replace('/\n$/', '',$line); // chomp
+        $rule = preg_split('/\s+/', $line);
+        list($discard,
+             $name,
+             $from,
+             $to,
+             $type,
+             $in,
+             $on,
+             $at,
+             $save,
+             $letter) = $rule;
+        if (isset($maxyear[$name])) {
+            if ($maxyear[$name] < $from) {
+                $maxyear[$name] = $from;
+            }
+        } else {
+            $maxyear[$name] = $from;
+        }
+        
+    }
+    
+    fseek($file, 0);
+    
     $rules = array();
     while ($line = fgets($file)) {
         // only pay attention to rules lines
@@ -224,7 +256,7 @@ function olson_simple_rule_parser ($filename) {
             $to = $from;
         }
         else if($to == 'max') {
-            $to = date('Y');
+            $to = $maxyear[$name];
         }
 
         for($i = $from; $i <= $to; ++$i) {