diff --git a/plugins/managesieve/managesieve.js b/plugins/managesieve/managesieve.js index c9b43fa6227..12338b51b2c 100644 --- a/plugins/managesieve/managesieve.js +++ b/plugins/managesieve/managesieve.js @@ -1007,10 +1007,14 @@ rcube_webmail.prototype.managesieve_tip_register = function (tips) { // format time string function sieve_formattime(hour, minutes) { - var i, c, h, time = '', format = rcmail.env.time_format || 'H:i'; - - for (i = 0; i < format.length; i++) { - c = format.charAt(i); + let time = ''; + const format = rcmail.env.time_format || 'H:i'; + + // Support all Time and Timezone related formatters from PHP + // https://www.php.net/manual/en/datetime.format.php + // Even if not all may make sense in this context + for (let i = 0; i < format.length; i++) { + const c = format.charAt(i); switch (c) { case 'a': time += hour >= 12 ? 'pm' : 'am'; @@ -1022,8 +1026,7 @@ function sieve_formattime(hour, minutes) { break; case 'g': case 'h': - h = hour == 0 ? 12 : hour > 12 ? hour - 12 : hour; - time += (c == 'h' && hour < 10 ? '0' : '') + hour; + time += (c === 'h' && hour < 10 ? '0' : '') + (hour % 12 === 0 ? 12 : hour % 12); break; case 'G': @@ -1040,6 +1043,30 @@ function sieve_formattime(hour, minutes) { break; case 's': time += '00'; + + break; + case 'u': // Microseconds + time += '000000'; + + break; + case 'v': // Milliseconds + time += '000'; + + break; + case 'e': // Timezone identifier + case 'I': // Whether the date is in daylight saving time + case 'O': // Difference to Greenwich time (GMT) without colon between hours and minutes + case 'P': // Difference to Greenwich time (GMT) with colon between hours and minutes + case 'p': // The same as P, but returns Z instead of +00:00 + case 'T': // Timezone abbreviation, if known; otherwise the GMT offset + case 'Z': // Timezone offset in seconds. The offset for timezones west of UTC is always negative, and for those east of UTC is always positive. + time += rcmail.env.server_timezone_info[c]; + + break; + case 'U': // Unix Timestamp + time += Math.round((new Date()).valueOf() / 1000); + + break; default: time += c; } diff --git a/plugins/managesieve/managesieve.php b/plugins/managesieve/managesieve.php index 1e160b60f83..f57b1dc850e 100644 --- a/plugins/managesieve/managesieve.php +++ b/plugins/managesieve/managesieve.php @@ -95,6 +95,22 @@ public function init_ui() $sieve_action = strpos($this->rc->action, 'plugin.managesieve') === 0; if ($this->rc->task == 'mail' || $sieve_action) { + // Injection of Timezone information into the JS Frontend. + // All the specifiers may be included in $config['time_format'] + // However not all are easily parseable in the JS world, especially + // when it comes to Timezone abbreviation + $tz = new DateTimeZone($this->rc->config->get('timezone')); + $dt = new DateTime('now', $tz); + + $this->rc->output->set_env('server_timezone_info', [ + 'e' => $dt->format('e'), + 'I' => $dt->format('I'), + 'O' => $dt->format('O'), + 'P' => $dt->format('P'), + 'p' => version_compare(\PHP_VERSION, '8.0.0') >= 0 ? $dt->format('p') : $dt->format('P'), + 'T' => $dt->format('T'), + 'Z' => $dt->format('Z'), + ]); $this->include_script('managesieve.js'); }