Changeset 1215

Show
Ignore:
Timestamp:
11/02/06 07:00:11 (2 years ago)
Author:
dominik
Message:

lots of fixes regarding the time calculation and gmt and dst offsets
fixed not generating final rules while non final rules are active
some typo fixes

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/src/config/AgaviTimeZoneDataParser.class.php

    r1210 r1215  
    136136 
    137137    $this->prepareRules($rules); 
     138    foreach($this->rules as $name => $rule) { 
     139      echo "rule $name:\n"; 
     140      foreach($rule['rules'] as $r) { 
     141        echo " rule ($r[time]  ".implode(',', array_keys($r))."): " . gmdate("d.m.Y H:i:s", $r['time']) . "\n"; 
     142      } 
     143      echo "\n"; 
     144    } 
    138145    $zones = $this->generateDatatables($zones); 
    139146 
     
    148155      $activeRules = array(); 
    149156      $myRules = array(); 
     157 
     158      $lastDstOff = 0; 
    150159 
    151160      $cnt = count($ruleList); 
     
    165174        do { 
    166175          $needsBreak = false; 
     176 
     177          $hasNonFinalRules = false; 
     178          // check if we have any active rules which are not final, so we need to process the final ones too 
     179          foreach($activeRules as $activeRule) { 
     180            if($activeRule['endYear'] != self::MAX_YEAR_VALUE) { 
     181              $hasNonFinalRules = true; 
     182              break; 
     183            } 
     184          } 
     185 
    167186          // remove all (still) active rules which don't apply anymore 
    168187          foreach($activeRules as $activeRuleIdx => $activeRule) { 
     
    173192              unset($activeRules[$activeRuleIdx]); 
    174193            // protect against generating final rules, they are handled in the timezone implementation 
    175             } elseif($year != $activeRule['startYear'] && $activeRule['endYear'] != self::MAX_YEAR_VALUE) { 
     194            } elseif($year != $activeRule['startYear'] && $hasNonFinalRules) { 
    176195              // if the year is the start year this rule has already been processed for this year 
    177               $time = $this->getOnDate($year, $activeRule['month'], $activeRule['on'], $myRule['at'], 0, $dstOff); 
     196              $time = $this->getOnDate($year, $activeRule['month'], $activeRule['on'], $myRule['at'], 0, 0); 
    178197              $myRules[] = array('time' => $time, 'rule' => $activeRule); 
    179198            } 
     
    181200 
    182201          if($year == $myRule['startYear']) { 
    183             $time = $this->getOnDate($year, $myRule['month'], $myRule['on'], $myRule['at'], 0, $dstOff); 
    184             if($myRule['endYear'] != self::MAX_YEAR_VALUE) { 
     202            $time = $this->getOnDate($year, $myRule['month'], $myRule['on'], $myRule['at'], 0, 0); 
     203 
     204            if($myRule['endYear'] != self::MAX_YEAR_VALUE || $hasNonFinalRules) { 
    185205              $myRules[] = array('time' => $time, 'rule' => $myRule); 
    186206            } 
     
    217237      throw new IllegalArgumentException('No rule with the name ' . $name . ' exists'); 
    218238    } 
     239 
     240    $lastDstOff = 0; 
    219241 
    220242    $rules = array(); 
     
    231253        $untilDate = $this->dateStrToArray($until); 
    232254        $untilTime = $this->getOnDate($untilDate['year'], $untilDate['month'], array('type' => 'date', 'date' => $untilDate['day'], 'day' => null), array('secondsInDay' => $untilDate['time']['seconds'], 'type' => $untilDate['time']['type']), $gmtOff, $dstOff); 
    233       } 
    234  
    235       switch($rule['rule']['on']['type']) { 
     255        var_dump("$until: $untilTime " . gmdate('d.m.Y H:i:s', $untilTime)); 
     256      } 
     257 
     258      switch($rule['rule']['at']['type']) { 
    236259        case 'wallclock': 
    237           $time -= $stdOff; 
    238           // the missing break is intentional ! 
     260          var_dump('wallclock on ' . $name . ' (' . gmdate('d.m.Y H:i:s', $time) . '): ' . $lastDstOff . ' ' . $gmtOff); 
     261          $time -= $lastDstOff; 
     262          $time -= $gmtOff; 
     263          break; 
     264 
    239265        case 'standard': 
     266          var_dump('standard on ' . $name . ' (' . gmdate('d.m.Y H:i:s', $time) . '):  ' . $gmtOff); 
    240267          $time -= $gmtOff; 
    241       } 
     268          break; 
     269      } 
     270 
     271      $lastDstOff = $dstOff; 
    242272 
    243273      if($from !== null && $time < $from) { 
     
    246276        continue; 
    247277      } elseif($firstHit) { 
    248         $insertRuleName = sprintf(is_array($format) ? $format[0] : $format, $lastSkippedRule !== null ? $lastSkippedRule['rule']['variablePart'] : ''); 
    249  
    250         $rules[] = array( 
    251           'time' => $from, 
    252           'rawOffset' => $gmtOff, 
    253           'dstOffset' => 0, 
    254           'name' => $insertRuleName, 
    255         ); 
     278        if($from != $time) { 
     279          $insertRuleName = sprintf(is_array($format) ? $format[0] : $format, $lastSkippedRule !== null ? $lastSkippedRule['rule']['variablePart'] : ''); 
     280 
     281          $rules[] = array( 
     282            'time' => $from, 
     283            'rawOffset' => $gmtOff, 
     284            'dstOffset' => 0, 
     285            'name' => $insertRuleName, 
     286          ); 
     287        } else { 
     288          var_dump("hit $from on $time " . gmdate('d.m.Y H:i:s', $time)); 
     289        } 
    256290        $firstHit = false; 
    257291      } 
     
    323357 
    324358          if($lastRuleEndTime !== null) { 
     359            var_dump("adding last role $format : $lastRuleEndTime " . gmdate("d.m.Y H:i:s", $lastRuleEndTime)); 
    325360            $myRules[] = array('time' => $lastRuleEndTime, 'rawOffset' => $gmtOff, 'dstOffset' => $dstOff, 'name' => $format); 
    326361          } else { 
     
    680715    $at = $ruleColumns[6]; 
    681716    $lastAtChar = substr($at, -1); 
    682     $atType = 'wallClock'; 
     717    $atType = 'wallclock'; 
    683718    if($lastAtChar == 'w') { 
    684719      $at = substr($at, 0, -1); 
     
    872907  protected function dateStrToArray($date) 
    873908  { 
    874     $array = array('year' => 0, 'month' => 1, 'day' => 1, 'time' => array('type' => 'wallclock', 'seconds' => 0)); 
     909    $array = array('year' => 0, 'month' => 0, 'day' => 1, 'time' => array('type' => 'wallclock', 'seconds' => 0)); 
    875910    if(preg_match('!(\d{4})(\s+[a-z0-9]+)?(\s+\d+)?(\s+\d[^\s]*)?!i', $date, $match)) { 
    876911      $match = array_map('trim', $match);