Display original time and timezone in iTip info box

This commit is contained in:
Aleksander Machniak 2021-12-17 11:26:48 +01:00
parent d870b2d374
commit ea78b1c2df
3 changed files with 51 additions and 26 deletions

View file

@ -3149,10 +3149,16 @@ $("#rcmfd_new_category").keypress(function(event) {
*/
private function mail_agenda_event_row($event, $class = '')
{
$time = !empty($event['allday']) ? $this->gettext('all-day') :
$this->rc->format_date($event['start'], $this->rc->config->get('time_format'))
. ' - ' .
$this->rc->format_date($event['end'], $this->rc->config->get('time_format'));
if (!empty($event['allday'])) {
$time = $this->gettext('all-day');
}
else {
$start = is_object($event['start']) ? clone $event['start'] : $event['start'];
$end = is_object($event['end']) ? clone $event['end'] : $event['end'];
$time = $this->rc->format_date($start, $this->rc->config->get('time_format'))
. ' - ' . $this->rc->format_date($end, $this->rc->config->get('time_format'));
}
return html::div(rtrim('event-row ' . ($class ?: $event['className'])),
html::span('event-date', $time)
@ -3217,7 +3223,7 @@ $("#rcmfd_new_category").keypress(function(event) {
// get prepared inline UI for this event object
if ($ical_objects->method) {
$append = '';
$date_str = $this->rc->format_date($event['start'], $this->rc->config->get('date_format'), empty($event['start']->_dateonly));
$date_str = $this->rc->format_date(clone $event['start'], $this->rc->config->get('date_format'), empty($event['start']->_dateonly));
$date = new DateTime($event['start']->format('Y-m-d') . ' 12:00:00', new DateTimeZone('UTC'));
// prepare a small agenda preview to be filled with actual event data on async request

View file

@ -136,7 +136,7 @@ class libcalendaring_itip
'name' => $bodytext,
'vars' => array(
'title' => $event['title'],
'date' => $this->lib->event_date_text($event, true) . $recurrence_info,
'date' => $this->lib->event_date_text($event) . $recurrence_info,
'attendees' => join(",\n ", $attendees_list),
'sender' => $this->sender['name'],
'organizer' => $this->sender['name'],

View file

@ -288,19 +288,43 @@ class libcalendaring extends rcube_plugin
/**
* Compose a date string for the given event
*/
public function event_date_text($event, $tzinfo = false)
public function event_date_text($event)
{
$fromto = '--';
$is_task = !empty($event['_type']) && $event['_type'] == 'task';
$this->date_format_defaults();
$date_format = self::to_php_date_format($this->rc->config->get('calendar_date_format', $this->defaults['calendar_date_format']));
$time_format = self::to_php_date_format($this->rc->config->get('calendar_time_format', $this->defaults['calendar_time_format']));
$getTimezone = function ($date) {
if ($newTz = $date->getTimezone()) {
return $newTz->getName();
}
return '';
};
$formatDate = function ($date, $format) use ($getTimezone) {
// This is a workaround for the rcmail::format_date() which does not play nice with timezone
$tz = $this->rc->config->get('timezone');
if ($dateTz = $getTimezone($date)) {
$this->rc->config->set('timezone', $dateTz);
}
$result = $this->rc->format_date($date, $format);
$this->rc->config->set('timezone', $tz);
return $result;
};
// handle task objects
if ($is_task && !empty($event['due']) && is_object($event['due'])) {
$date_format = !empty($event['due']->_dateonly) ? self::to_php_date_format($this->rc->config->get('calendar_date_format', $this->defaults['calendar_date_format'])) : null;
$fromto = $this->rc->format_date($event['due'], $date_format, false);
$fromto = $formatDate($event['due'], !empty($event['due']->_dateonly) ? $date_format : null);
// add timezone information
if ($fromto && $tzinfo && ($tzname = $this->timezone->getName())) {
$fromto .= ' (' . strtr($tzname, '_', ' ') . ')';
if ($fromto && empty($event['due']->_dateonly) && ($tz = $getTimezone($event['due']))) {
$fromto .= ' (' . strtr($tz, '_', ' ') . ')';
}
return $fromto;
@ -311,29 +335,24 @@ class libcalendaring extends rcube_plugin
return $fromto;
}
$duration = $event['start']->diff($event['end'])->format('s');
$this->date_format_defaults();
$date_format = self::to_php_date_format($this->rc->config->get('calendar_date_format', $this->defaults['calendar_date_format']));
$time_format = self::to_php_date_format($this->rc->config->get('calendar_time_format', $this->defaults['calendar_time_format']));
if ($event['allday']) {
$fromto = $this->rc->format_date($event['start'], $date_format, false);
if (($todate = $this->rc->format_date($event['end'], $date_format, false)) != $fromto)
$fromto = $formatDate($event['start'], $date_format);
if (($todate = $formatDate($event['end'], $date_format)) != $fromto) {
$fromto .= ' - ' . $todate;
}
}
else if ($duration < 86400 && $event['start']->format('d') == $event['end']->format('d')) {
$fromto = $this->rc->format_date($event['start'], $date_format) . ' ' . $this->rc->format_date($event['start'], $time_format) .
' - ' . $this->rc->format_date($event['end'], $time_format);
else if ($event['start']->format('Ymd') === $event['end']->format('Ymd')) {
$fromto = $formatDate($event['start'], $date_format) . ' ' . $formatDate($event['start'], $time_format) .
' - ' . $formatDate($event['end'], $time_format);
}
else {
$fromto = $this->rc->format_date($event['start'], $date_format) . ' ' . $this->rc->format_date($event['start'], $time_format) .
' - ' . $this->rc->format_date($event['end'], $date_format) . ' ' . $this->rc->format_date($event['end'], $time_format);
$fromto = $formatDate($event['start'], $date_format) . ' ' . $formatDate($event['start'], $time_format) .
' - ' . $formatDate($event['end'], $date_format) . ' ' . $formatDate($event['end'], $time_format);
}
// add timezone information
if ($tzinfo && ($tzname = $this->timezone->getName())) {
$fromto .= ' (' . strtr($tzname, '_', ' ') . ')';
if ($fromto && empty($event['allday']) && ($tz = $getTimezone($event['start']))) {
$fromto .= ' (' . strtr($tz, '_', ' ') . ')';
}
return $fromto;