Fix anually recurrence end date on 32bit systems by replacing (overflowing) unix timestamps with DateTime objects (#2613)
This commit is contained in:
parent
8a820d1994
commit
965a9b74b3
5 changed files with 15 additions and 13 deletions
|
@ -101,7 +101,7 @@ class kolab_date_recurrence
|
||||||
/**
|
/**
|
||||||
* Get the end date of the occurence of this recurrence cycle
|
* Get the end date of the occurence of this recurrence cycle
|
||||||
*
|
*
|
||||||
* @return mixed Timestamp with end date of the last event or False if recurrence exceeds limit
|
* @return DateTime|bool End datetime of the last event or False if recurrence exceeds limit
|
||||||
*/
|
*/
|
||||||
public function end()
|
public function end()
|
||||||
{
|
{
|
||||||
|
@ -109,25 +109,25 @@ class kolab_date_recurrence
|
||||||
|
|
||||||
// recurrence end date is given
|
// recurrence end date is given
|
||||||
if ($event['recurrence']['UNTIL'] instanceof DateTime) {
|
if ($event['recurrence']['UNTIL'] instanceof DateTime) {
|
||||||
return $event['recurrence']['UNTIL']->format('U');
|
return $event['recurrence']['UNTIL'];
|
||||||
}
|
}
|
||||||
|
|
||||||
// let libkolab do the work
|
// let libkolab do the work
|
||||||
if ($this->engine && ($cend = $this->engine->getLastOccurrence()) && ($end_dt = kolab_format::php_datetime(new cDateTime($cend)))) {
|
if ($this->engine && ($cend = $this->engine->getLastOccurrence()) && ($end_dt = kolab_format::php_datetime(new cDateTime($cend)))) {
|
||||||
return $end_dt->format('U');
|
return $end_dt;
|
||||||
}
|
}
|
||||||
|
|
||||||
// determine a reasonable end date if none given
|
// determine a reasonable end date if none given
|
||||||
if (!$event['recurrence']['COUNT'] && $event['start'] instanceof DateTime) {
|
if (!$event['recurrence']['COUNT'] && $event['end'] instanceof DateTime) {
|
||||||
switch ($event['recurrence']['FREQ']) {
|
switch ($event['recurrence']['FREQ']) {
|
||||||
case 'YEARLY': $intvl = 'P100Y'; break;
|
case 'YEARLY': $intvl = 'P100Y'; break;
|
||||||
case 'MONTHLY': $intvl = 'P20Y'; break;
|
case 'MONTHLY': $intvl = 'P20Y'; break;
|
||||||
default: $intvl = 'P10Y'; break;
|
default: $intvl = 'P10Y'; break;
|
||||||
}
|
}
|
||||||
|
|
||||||
$end_dt = clone $event['start'];
|
$end_dt = clone $event['end'];
|
||||||
$end_dt->add(new DateInterval($intvl));
|
$end_dt->add(new DateInterval($intvl));
|
||||||
return $end_dt->format('U');
|
return $end_dt;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -24,6 +24,8 @@
|
||||||
|
|
||||||
class kolab_storage_cache
|
class kolab_storage_cache
|
||||||
{
|
{
|
||||||
|
const DB_DATE_FORMAT = 'Y-m-d H:i:s';
|
||||||
|
|
||||||
protected $db;
|
protected $db;
|
||||||
protected $imap;
|
protected $imap;
|
||||||
protected $folder;
|
protected $folder;
|
||||||
|
|
|
@ -34,14 +34,14 @@ class kolab_storage_cache_event extends kolab_storage_cache
|
||||||
{
|
{
|
||||||
$sql_data = parent::_serialize($object);
|
$sql_data = parent::_serialize($object);
|
||||||
|
|
||||||
// database runs in server's timezone so using date() is what we want
|
$sql_data['dtstart'] = is_object($object['start']) ? $object['start']->format(self::DB_DATE_FORMAT) : date(self::DB_DATE_FORMAT, $object['start']);
|
||||||
$sql_data['dtstart'] = date('Y-m-d H:i:s', is_object($object['start']) ? $object['start']->format('U') : $object['start']);
|
$sql_data['dtend'] = is_object($object['end']) ? $object['end']->format(self::DB_DATE_FORMAT) : date(self::DB_DATE_FORMAT, $object['end']);
|
||||||
$sql_data['dtend'] = date('Y-m-d H:i:s', is_object($object['end']) ? $object['end']->format('U') : $object['end']);
|
|
||||||
|
|
||||||
// extend date range for recurring events
|
// extend date range for recurring events
|
||||||
if ($object['recurrence'] && $object['_formatobj']) {
|
if ($object['recurrence'] && $object['_formatobj']) {
|
||||||
$recurrence = new kolab_date_recurrence($object['_formatobj']);
|
$recurrence = new kolab_date_recurrence($object['_formatobj']);
|
||||||
$sql_data['dtend'] = date('Y-m-d 23:59:59', $recurrence->end() ?: strtotime('now +10 years'));
|
$dtend = $recurrence->end() ?: new DateTime('now +10 years');
|
||||||
|
$sql_data['dtend'] = $dtend->format(self::DB_DATE_FORMAT);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $sql_data;
|
return $sql_data;
|
||||||
|
|
|
@ -35,9 +35,9 @@ class kolab_storage_cache_task extends kolab_storage_cache
|
||||||
$sql_data = parent::_serialize($object) + array('dtstart' => null, 'dtend' => null);
|
$sql_data = parent::_serialize($object) + array('dtstart' => null, 'dtend' => null);
|
||||||
|
|
||||||
if ($object['start'])
|
if ($object['start'])
|
||||||
$sql_data['dtstart'] = date('Y-m-d H:i:s', is_object($object['start']) ? $object['start']->format('U') : $object['start']);
|
$sql_data['dtstart'] = is_object($object['start']) ? $object['start']->format(self::DB_DATE_FORMAT) : date(self::DB_DATE_FORMAT, $object['start']);
|
||||||
if ($object['due'])
|
if ($object['due'])
|
||||||
$sql_data['dtend'] = date('Y-m-d H:i:s', is_object($object['due']) ? $object['due']->format('U') : $object['due']);
|
$sql_data['dtend'] = is_object($object['due']) ? $object['due']->format(self::DB_DATE_FORMAT) : date(self::DB_DATE_FORMAT, $object['due']);
|
||||||
|
|
||||||
return $sql_data;
|
return $sql_data;
|
||||||
}
|
}
|
||||||
|
|
|
@ -809,7 +809,7 @@ class kolab_storage_folder
|
||||||
$recurrence = new kolab_date_recurrence($object['_formatobj']);
|
$recurrence = new kolab_date_recurrence($object['_formatobj']);
|
||||||
if ($end = $recurrence->end()) {
|
if ($end = $recurrence->end()) {
|
||||||
unset($exception['recurrence']['COUNT']);
|
unset($exception['recurrence']['COUNT']);
|
||||||
$exception['recurrence']['UNTIL'] = new DateTime('@'.$end);
|
$exception['recurrence']['UNTIL'] = $end;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue