Improve recurrence text so description for RDATE is better (#5401)
This commit is contained in:
parent
6bb5511b6d
commit
37a4b8c696
1 changed files with 49 additions and 52 deletions
|
@ -771,77 +771,74 @@ class libcalendaring extends rcube_plugin
|
|||
*/
|
||||
public function recurrence_text($rrule)
|
||||
{
|
||||
// derive missing FREQ and INTERVAL from RDATE list
|
||||
$limit = 10;
|
||||
$exdates = array();
|
||||
$format = $this->rc->config->get('calendar_date_format', $this->defaults['calendar_date_format']);
|
||||
$format = self::to_php_date_format($format);
|
||||
$format_fn = function($dt) use ($format) {
|
||||
return rcmail::get_instance()->format_date($dt, $format);
|
||||
};
|
||||
|
||||
if (is_array($rrule['EXDATE']) && !empty($rrule['EXDATE'])) {
|
||||
$exdates = array_map($format_fn, $rrule['EXDATE']);
|
||||
}
|
||||
|
||||
if (empty($rrule['FREQ']) && !empty($rrule['RDATE'])) {
|
||||
$first = $rrule['RDATE'][0];
|
||||
$second = $rrule['RDATE'][1];
|
||||
$third = $rrule['RDATE'][2];
|
||||
if (is_a($first, 'DateTime') && is_a($second, 'DateTime')) {
|
||||
$diff = $first->diff($second);
|
||||
foreach (array('y' => 'YEARLY', 'm' => 'MONTHLY', 'd' => 'DAILY') as $k => $freq) {
|
||||
if ($diff->$k != 0) {
|
||||
$rrule['FREQ'] = $freq;
|
||||
$rrule['INTERVAL'] = $diff->$k;
|
||||
$rdates = array_map($format_fn, $rrule['RDATE']);
|
||||
|
||||
// verify interval with next item
|
||||
if (is_a($third, 'DateTime')) {
|
||||
$diff2 = $second->diff($third);
|
||||
if ($diff2->$k != $diff->$k) {
|
||||
unset($rrule['INTERVAL']);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!$rrule['INTERVAL']) {
|
||||
$rrule['FREQ'] = 'RDATE';
|
||||
}
|
||||
$rrule['UNTIL'] = end($rrule['RDATE']);
|
||||
if (!empty($exdates)) {
|
||||
$rdates = array_diff($rdates, $exdates);
|
||||
}
|
||||
|
||||
$freq = sprintf('%s %d ', $this->gettext('every'), $rrule['INTERVAL']);
|
||||
$details = '';
|
||||
if (count($rdates) > $limit) {
|
||||
$rdates = array_slice($rdates, 0, $limit);
|
||||
$more = true;
|
||||
}
|
||||
|
||||
return $this->gettext('ondate') . ' ' . join(', ', $rdates)
|
||||
. ($more ? '...' : '');
|
||||
}
|
||||
|
||||
$output = sprintf('%s %d ', $this->gettext('every'), $rrule['INTERVAL'] ?: 1);
|
||||
|
||||
switch ($rrule['FREQ']) {
|
||||
case 'DAILY':
|
||||
$freq .= $this->gettext('days');
|
||||
$output .= $this->gettext('days');
|
||||
break;
|
||||
case 'WEEKLY':
|
||||
$freq .= $this->gettext('weeks');
|
||||
$output .= $this->gettext('weeks');
|
||||
break;
|
||||
case 'MONTHLY':
|
||||
$freq .= $this->gettext('months');
|
||||
$output .= $this->gettext('months');
|
||||
break;
|
||||
case 'YEARLY':
|
||||
$freq .= $this->gettext('years');
|
||||
$output .= $this->gettext('years');
|
||||
break;
|
||||
}
|
||||
|
||||
if ($rrule['INTERVAL'] <= 1) {
|
||||
$freq = $this->gettext(strtolower($rrule['FREQ']));
|
||||
}
|
||||
|
||||
if ($rrule['COUNT']) {
|
||||
$until = $this->gettext(array('name' => 'forntimes', 'vars' => array('nr' => $rrule['COUNT'])));
|
||||
}
|
||||
else if ($rrule['UNTIL']) {
|
||||
$until = $this->gettext('recurrencend') . ' ' . $this->rc->format_date($rrule['UNTIL'], self::to_php_date_format($this->rc->config->get('calendar_date_format', $this->defaults['calendar_date_format'])));
|
||||
$until = $this->gettext('recurrencend') . ' ' . $this->rc->format_date($rrule['UNTIL'], $format);
|
||||
}
|
||||
else {
|
||||
$until = $this->gettext('forever');
|
||||
}
|
||||
|
||||
$except = '';
|
||||
if (is_array($rrule['EXDATE']) && !empty($rrule['EXDATE'])) {
|
||||
$format = self::to_php_date_format($this->rc->config->get('calendar_date_format', $this->defaults['calendar_date_format']));
|
||||
$exdates = array_map(
|
||||
function($dt) use ($format) { return rcmail::get_instance()->format_date($dt, $format); },
|
||||
array_slice($rrule['EXDATE'], 0, 10)
|
||||
);
|
||||
$except = '; ' . $this->gettext('except') . ' ' . join(', ', $exdates);
|
||||
$output .= ', ' . $until;
|
||||
|
||||
if (!empty($exdates)) {
|
||||
if (count($exdates) > $limit) {
|
||||
$exdates = array_slice($exdates, 0, $limit);
|
||||
$more = true;
|
||||
}
|
||||
|
||||
return rtrim($freq . $details . ', ' . $until . $except);
|
||||
$output = '; ' . $this->gettext('except') . ' ' . join(', ', $exdates)
|
||||
. ($more ? '...' : '');
|
||||
}
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Reference in a new issue