From 9aae1b7fc399b5d2cecb8f0d0df6a2ae4e749786 Mon Sep 17 00:00:00 2001 From: Aleksander Machniak Date: Fri, 26 Jun 2015 09:20:43 +0200 Subject: [PATCH] Fix so microseconds macro (u) in log_date_format works (#1490446) --- CHANGELOG | 1 + program/lib/Roundcube/rcube.php | 6 +----- program/lib/Roundcube/rcube_utils.php | 23 +++++++++++++++++++++++ 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index c838f49bf..ff9e5d926 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -10,6 +10,7 @@ CHANGELOG Roundcube Webmail - Plugin API: Added message_ready hook - Plugin API: Add special onload() method to execute plugin actions before startup (session and GUI initialization) - Implemented UI element to jump to specified page of the messages list (#1485235) +- Fix so microseconds macro (u) in log_date_format works (#1490446) - Fix so unrecognized TNEF attachments are displayed on the list of attachments (#1490351) - Fix "Importing..." message does not hide on error (#1490422) - Fix Compose action in addressbook for results from multiple addressbooks (#1490413) diff --git a/program/lib/Roundcube/rcube.php b/program/lib/Roundcube/rcube.php index 6b0c6b8a3..02e11e2bb 100644 --- a/program/lib/Roundcube/rcube.php +++ b/program/lib/Roundcube/rcube.php @@ -1231,11 +1231,7 @@ class rcube $session_key = intval(self::$instance->config->get('log_session_id', 8)); } - if (empty($date_format)) { - $date_format = 'd-M-Y H:i:s O'; - } - - $date = date($date_format); + $date = rcube_utils::date_format($date_format); // trigger logging hook if (is_object(self::$instance) && is_object(self::$instance->plugins)) { diff --git a/program/lib/Roundcube/rcube_utils.php b/program/lib/Roundcube/rcube_utils.php index 00311f01f..23fc3f823 100644 --- a/program/lib/Roundcube/rcube_utils.php +++ b/program/lib/Roundcube/rcube_utils.php @@ -1149,4 +1149,27 @@ class rcube_utils return $random; } + + /** + * Format current date according to specified format. + * This method supports microseconds (u). + * + * @param string $format Date format (default: 'd-M-Y H:i:s O') + * + * @return string Formatted date + */ + public static function date_format($format = null) + { + if (empty($format)) { + $format = 'd-M-Y H:i:s O'; + } + + if (strpos($format, 'u') !== false + && ($date = date_create_from_format('U.u.e', microtime(true) . '.' . date_default_timezone_get())) + ) { + return $date->format($format); + } + + return date($format); + } }