Browse Source

Fix so output of log_date_format with microseconds contains time in server time zone, not UTC

pull/9596/head
Aleksander Machniak 2 years ago
parent
commit
56a1d651f0
  1. 1
      CHANGELOG.md
  2. 11
      program/lib/Roundcube/rcube_utils.php
  3. 16
      tests/Framework/Utils.php

1
CHANGELOG.md

@ -2,6 +2,7 @@
## Unreleased
- Fix so output of log_date_format with microseconds contains time in server time zone, not UTC
- Fix so N property always exists in a vCard export (#8771)
- Fix so rcmail::format_date() works with DateTimeImmutable input (#8867)
- Fix bug where a non-ASCII character in app.js could cause error in javascript engine (#8894)

11
program/lib/Roundcube/rcube_utils.php

@ -1479,12 +1479,17 @@ class rcube_utils
}
if (strpos($format, 'u') !== false) {
$dt = number_format(microtime(true), 6, '.', '');
$dt .= '.' . date_default_timezone_get();
$dt = number_format(microtime(true), 6, '.', '');
try {
$date = date_create_from_format('U.u', $dt);
$date->setTimeZone(new DateTimeZone(date_default_timezone_get()));
if ($date = date_create_from_format('U.u.e', $dt)) {
return $date->format($format);
}
catch (Exception) {
// ignore, fallback to date()
}
}
return date($format);

16
tests/Framework/Utils.php

@ -7,6 +7,22 @@
*/
class Framework_Utils extends PHPUnit\Framework\TestCase
{
/**
* Test for rcube_utils::date_format()
*/
function test_date_format()
{
date_default_timezone_set('Europe/Berlin');
$this->assertSame(date('d-M-Y H:i:s O'), rcube_utils::date_format());
$this->assertSame(date('Y-m-d H:i:s O'), rcube_utils::date_format('Y-m-d H:i:s O'));
$result = rcube_utils::date_format('H:i:s,u O');
$regexp = '/^' . preg_quote(date('H:i:s,')) . '(?<!000000)\d{6}' . preg_quote(date(' O')) . '$/';
$this->assertMatchesRegularExpression($regexp, $result);
}
/**
* Test for rcube_utils::explode()
*/

Loading…
Cancel
Save