Posted By

althaus on 11/19/10


Tagged

DateTime Davical


Versions (?)

RepeatRuleDateTime


 / Published in: PHP
 

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

  1. public function __construct($date = null, $dtz = null) {
  2. $this->is_date = false;
  3. if ( preg_match('{;?VALUE=DATE[:;]}', $date, $matches) ) $this->is_date = true;
  4. 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;
  5. if (preg_match('/;?TZID=([^:]+).*:(\d{8}(T\d{6})?)(Z)?/', $date, $matches) ) {
  6. if ( isset($matches[4]) && $matches[4] == 'Z' ) {
  7. $dtz = new RepeatRuleTimeZone('UTC');
  8. $this->tzid = 'UTC';
  9. }
  10. else if ( isset($matches[1]) && $matches[1] != '' ) {
  11. $dtz = new RepeatRuleTimeZone($matches[1]);
  12. $this->tzid = $dtz->tzid();
  13. }
  14. else {
  15. $dtz = new RepeatRuleTimeZone('UTC');
  16. $this->tzid = null;
  17. }
  18. $date = $matches[2];
  19. }
  20. elseif ( is_string($dtz) ) {
  21. $dtz = new RepeatRuleTimeZone($dtz);
  22. $this->tzid = $dtz->tzid();
  23. }
  24. elseif( $dtz === null ) {
  25. $dtz = new RepeatRuleTimeZone('UTC');
  26. if ( preg_match('/(\d{8}(T\d{6})?)Z/', $date, $matches) ) {
  27. if ( strlen($matches[1]) == 8 ) $this->is_date = true;
  28. $this->tzid = 'UTC';
  29. }
  30. else {
  31. $this->tzid = null;
  32. }
  33. }
  34. else {
  35. $this->tzid = $dtz->getName();
  36. }
  37. parent::__construct($date, $dtz);
  38.  
  39. return $this;
  40. }

Report this snippet  

You need to login to post a comment.