Fix date/time format issies and inconsistencies, remove confusing config

This commit is contained in:
Aleksander Machniak 2019-01-08 11:39:10 +01:00
parent b0196c7ff1
commit d08e8a8a3b
3 changed files with 30 additions and 61 deletions

View file

@ -34,33 +34,6 @@ $config['calendar_default_view'] = "agendaWeek";
// show a birthdays calendar from the user's address book(s)
$config['calendar_contact_birthdays'] = false;
// mapping of Roundcube date formats to calendar formats (long/short/agenda)
// should be in sync with 'date_formats' in main config
$config['calendar_date_format_sets'] = array(
'yyyy-MM-dd' => array('MMM d yyyy', 'M-d', 'ddd MM-dd'),
'dd-MM-yyyy' => array('d MMM yyyy', 'd-M', 'ddd dd-MM'),
'yyyy/MM/dd' => array('MMM d yyyy', 'M/d', 'ddd MM/dd'),
'MM/dd/yyyy' => array('MMM d yyyy', 'M/d', 'ddd MM/dd'),
'dd/MM/yyyy' => array('d MMM yyyy', 'd/M', 'ddd dd/MM'),
'dd.MM.yyyy' => array('dd. MMM yyyy', 'd.M', 'ddd dd.MM.'),
'd.M.yyyy' => array('d. MMM yyyy', 'd.M', 'ddd d.MM.'),
);
// general date format (only set if different from default date format and not user configurable)
// $config['calendar_date_format'] = "yyyy-MM-dd";
// time format (only set if different from default date format)
// $config['calendar_time_format'] = "HH:mm";
// short date format (used for column titles)
// $config['calendar_date_short'] = 'M-d';
// long date format (used for calendar title)
// $config['calendar_date_long'] = 'MMM d yyyy';
// date format used for agenda view
// $config['calendar_date_agenda'] = 'ddd MM-dd';
// timeslots per hour (1, 2, 3, 4, 6)
$config['calendar_timeslots'] = 2;

View file

@ -46,8 +46,10 @@ function rcube_libcalendaring(settings)
// general datepicker settings
this.datepicker_settings = {
// translate from fullcalendar format to datepicker format
dateFormat: settings.date_format.replace(/M/g, 'm').replace(/mmmmm/, 'MM').replace(/mmm/, 'M').replace(/dddd/, 'DD').replace(/ddd/, 'D').replace(/DD/, 'dd').replace(/Y/g, 'y').replace(/yyyy/g, 'yy'),
// translate from fullcalendar (MomentJS) format to datepicker format
dateFormat: settings.date_format.replace(/M/g, 'm').replace(/mmmm/, 'MM').replace(/mmm/, 'M')
.replace(/dddd/, 'DD').replace(/ddd/, 'D').replace(/DD/, 'dd')
.replace(/Y/g, 'y').replace(/yyyy/, 'yy'),
firstDay : settings.first_day,
dayNamesMin: settings.days_short,
monthNames: settings.months,
@ -281,10 +283,8 @@ function rcube_libcalendaring(settings)
hh : function(d) { return zeroPad(d.getHours() % 12 || 12) },
H : function(d) { return d.getHours() },
HH : function(d) { return zeroPad(d.getHours()) },
t : function(d) { return d.getHours() < 12 ? 'a' : 'p' },
tt : function(d) { return d.getHours() < 12 ? 'am' : 'pm' },
T : function(d) { return d.getHours() < 12 ? 'A' : 'P' },
TT : function(d) { return d.getHours() < 12 ? 'AM' : 'PM' }
a : function(d) { return d.getHours() < 12 ? 'am' : 'pm' },
A : function(d) { return d.getHours() < 12 ? 'AM' : 'PM' }
};
var i, i2, c, formatter, res = '',

View file

@ -40,21 +40,21 @@ class libcalendaring extends rcube_plugin
public $ical_message;
public $defaults = array(
'calendar_date_format' => "yyyy-MM-dd",
'calendar_date_short' => "M-d",
'calendar_date_long' => "MMM d yyyy",
'calendar_date_agenda' => "ddd MM-dd",
'calendar_time_format' => "HH:mm",
'calendar_date_format' => "Y-m-d",
'calendar_date_short' => "M-j",
'calendar_date_long' => "F j Y",
'calendar_date_agenda' => "l M-d",
'calendar_time_format' => "H:m",
'calendar_first_day' => 1,
'calendar_first_hour' => 6,
'calendar_date_format_sets' => array(
'yyyy-MM-dd' => array('MMM d yyyy', 'M-d', 'ddd MM-dd'),
'dd-MM-yyyy' => array('d MMM yyyy', 'd-M', 'ddd dd-MM'),
'yyyy/MM/dd' => array('MMM d yyyy', 'M/d', 'ddd MM/dd'),
'MM/dd/yyyy' => array('MMM d yyyy', 'M/d', 'ddd MM/dd'),
'dd/MM/yyyy' => array('d MMM yyyy', 'd/M', 'ddd dd/MM'),
'dd.MM.yyyy' => array('dd. MMM yyyy', 'd.M', 'ddd dd.MM.'),
'd.M.yyyy' => array('d. MMM yyyy', 'd.M', 'ddd d.MM.'),
'Y-m-d' => array('d M Y', 'm-d', 'l m-d'),
'd-m-Y' => array('d M Y', 'd-m', 'l d-m'),
'Y/m/d' => array('M d Y', 'm/d', 'l m/d'),
'm/d/Y' => array('M d Y', 'm/d', 'l m/d'),
'd/m/Y' => array('d M Y', 'd/m', 'l d/m'),
'd.m.Y' => array('d. M Y', 'd.m', 'l d.m.'),
'd.m.Y' => array('d. M Y', 'd.m', 'l d.m.'),
),
);
@ -211,12 +211,10 @@ class libcalendaring extends rcube_plugin
foreach ($keys as $key) {
$settings[$key] = (string)$this->rc->config->get('calendar_' . $key, $this->defaults['calendar_' . $key]);
$settings[$key] = str_replace('y', 'Y', $settings[$key]);
$settings[$key] = preg_replace('/(?<!d)dd(?!d)/', 'DD', $settings[$key]);
$settings[$key] = preg_replace('/(?<!d)d(?!d)/', 'D', $settings[$key]);
$settings[$key] = self::from_php_date_format($settings[$key]);
}
$settings['dates_long'] = $settings['date_long'];// . " - " . $settings['date_long'];
$settings['dates_long'] = $settings['date_long'];
$settings['first_day'] = (int)$this->rc->config->get('calendar_first_day', $this->defaults['calendar_first_day']);
$settings['timezone'] = $this->timezone_offset;
$settings['dst'] = $this->dst_active;
@ -267,8 +265,8 @@ class libcalendaring extends rcube_plugin
if (isset($defaults['date_format']))
return;
$defaults['date_format'] = $this->rc->config->get('calendar_date_format', self::from_php_date_format($this->rc->config->get('date_format')));
$defaults['time_format'] = $this->rc->config->get('calendar_time_format', self::from_php_date_format($this->rc->config->get('time_format')));
$defaults['date_format'] = $this->rc->config->get('calendar_date_format', $this->rc->config->get('date_format'));
$defaults['time_format'] = $this->rc->config->get('calendar_time_format', $this->rc->config->get('time_format'));
// override defaults
if ($defaults['date_format'])
@ -1499,31 +1497,29 @@ class libcalendaring extends rcube_plugin
}
/**
* Convert from PHP date() format to fullcalendar format string
* Convert from PHP date() format to fullcalendar (MomentJS) format string
*/
public static function from_php_date_format($from)
{
// "d.m.Y H:i:s" => "dd.MM.yyyy HH:mm:ss"
return strtr($from, array(
'y' => 'yy',
'Y' => 'yyyy',
'y' => 'YY',
'Y' => 'YYYY',
'M' => 'MMM',
'F' => 'MMMM',
'm' => 'MM',
'n' => 'M',
'j' => 'd',
'd' => 'dd',
'D' => 'ddd',
'l' => 'dddd',
'j' => 'D',
'd' => 'DD',
'D' => 'DDD',
'l' => 'DDDD',
'H' => 'HH',
'h' => 'hh',
'G' => 'H',
'g' => 'h',
'i' => 'mm',
's' => 'ss',
'A' => 'TT',
'a' => 'tt',
'c' => 'u',
'c' => '',
));
}