Skip to content

Commit

Permalink
Sort end date, regardless of if it's a timestamp or year.
Browse files Browse the repository at this point in the history
  • Loading branch information
mrubinsk committed Feb 7, 2017
1 parent 5576e03 commit abafeee
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion framework/Icalendar/lib/Horde/Icalendar.php
Expand Up @@ -1289,7 +1289,7 @@ function($a, $b) {
if (!$b['end']) {
return -1;
}
return $a['end'] - $b['end'];
return $this->_getEndDifference($a['end'], $b['end']);
}
);

Expand Down Expand Up @@ -1342,6 +1342,31 @@ protected function _checkEndDate($t, $times)
return ($t < $times['end']);
}

/**
* Returns the difference between the datetime indicated by $a and the
* datetime indicated by $b after normalizing both values to a unix
* timestamp. Used when sorting timezone transitions that may contain
* mixed format end times.
*
* @param mixed Either a string representing a 4 digit year, or unix
* timestamp.
* @param mixed Either a string representing a 4 digit year, or unix
* timestamp.
*
* @return boolean True if $a < $b otherwise false.
*/
protected function _getEndDifference($a, $b)
{
if (strlen($a) == 4) {
$a = @gmmktime(0, 0, 0, 1, 1, $a);
}
if (strlen($b) == 4) {
$b = @gmmktime(0, 0, 0, 1, 1, $b);
}

return $a - $b;
}

/**
* Parses a DateTime field and returns a unix timestamp. If the
* field cannot be parsed then the original text is returned
Expand Down

0 comments on commit abafeee

Please sign in to comment.