From f476ae28ebf7437bdaca0ef3cf55079e07342938 Mon Sep 17 00:00:00 2001 From: mattc-catalyst Date: Tue, 2 Oct 2007 01:43:07 +0000 Subject: [PATCH] MDL-11538: lib/olson - bugfix, olson time-zone import doesn't deal with rule changes in the future Author: Matt Clarkson --- lib/olson.php | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/lib/olson.php b/lib/olson.php index ac83492363..9b185e8249 100644 --- a/lib/olson.php +++ b/lib/olson.php @@ -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) { -- 2.39.5