From d08e8a8a3b4f97781cd1980b714886507d129cf5 Mon Sep 17 00:00:00 2001 From: Aleksander Machniak Date: Tue, 8 Jan 2019 11:39:10 +0100 Subject: [PATCH] Fix date/time format issies and inconsistencies, remove confusing config --- plugins/calendar/config.inc.php.dist | 27 ------------ plugins/libcalendaring/libcalendaring.js | 12 +++--- plugins/libcalendaring/libcalendaring.php | 52 +++++++++++------------ 3 files changed, 30 insertions(+), 61 deletions(-) diff --git a/plugins/calendar/config.inc.php.dist b/plugins/calendar/config.inc.php.dist index f80d3eb0..6ffdd581 100644 --- a/plugins/calendar/config.inc.php.dist +++ b/plugins/calendar/config.inc.php.dist @@ -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; diff --git a/plugins/libcalendaring/libcalendaring.js b/plugins/libcalendaring/libcalendaring.js index 57ea2342..9c151bbb 100644 --- a/plugins/libcalendaring/libcalendaring.js +++ b/plugins/libcalendaring/libcalendaring.js @@ -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 = '', diff --git a/plugins/libcalendaring/libcalendaring.php b/plugins/libcalendaring/libcalendaring.php index 4fc1c9bd..d79a0b8e 100644 --- a/plugins/libcalendaring/libcalendaring.php +++ b/plugins/libcalendaring/libcalendaring.php @@ -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('/(?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' => '', )); }