Return to Snippet

Revision: 36238
at November 19, 2010 19:44 by althaus


Initial Code
public function __construct($date = null, $dtz = null) {
    $this->is_date = false;
    if ( preg_match('{;?VALUE=DATE[:;]}', $date, $matches) ) $this->is_date = true;
    elseif ( preg_match('{:([12]\d{3}) (0[1-9]|1[012]) (0[1-9]|[12]\d|3[01]Z?) $}x', $date, $matches) ) $this->is_date = true;
    if (preg_match('/;?TZID=([^:]+).*:(\d{8}(T\d{6})?)(Z)?/', $date, $matches) ) {
      if ( isset($matches[4]) && $matches[4] == 'Z' ) {
        $dtz = new RepeatRuleTimeZone('UTC');
        $this->tzid = 'UTC';
      }
      else if ( isset($matches[1]) && $matches[1] != '' ) {
        $dtz = new RepeatRuleTimeZone($matches[1]);
        $this->tzid = $dtz->tzid();
      }
      else {
        $dtz = new RepeatRuleTimeZone('UTC');
        $this->tzid = null;
      }
      $date = $matches[2];
    }
    elseif ( is_string($dtz) ) {
      $dtz = new RepeatRuleTimeZone($dtz);
      $this->tzid = $dtz->tzid();
    }
    elseif( $dtz === null ) {
      $dtz = new RepeatRuleTimeZone('UTC');
      if ( preg_match('/(\d{8}(T\d{6})?)Z/', $date, $matches) ) {
        if ( strlen($matches[1]) == 8 ) $this->is_date = true;
        $this->tzid = 'UTC';
      }
      else {
        $this->tzid = null;
      }
    }
    else {
      $this->tzid = $dtz->getName();
    }
    parent::__construct($date, $dtz);

    return $this;
  }

Initial URL


Initial Description
Added "$date = $matches[2];" to prevent exception when putting dates like "TZID=Europe/Berlin:20101110T140000" into the constructor.

Initial Title
RepeatRuleDateTime

Initial Tags


Initial Language
PHP