mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-07-08 22:18:28 +03:00
Replaced sTimeOffset with sTimeZone to prevent DST issues
This commit is contained in:
parent
849b1b9607
commit
605f3acbf4
5 changed files with 18 additions and 49 deletions
|
|
@ -95,30 +95,4 @@ abstract class DateTimeHelper
|
|||
|
||||
return \MailSo\Base\DateTimeHelper::ParseDateStringType1($sDateTime);
|
||||
}
|
||||
|
||||
public static function TimeToSec(string $sTime) : int
|
||||
{
|
||||
$iMod = 1;
|
||||
$sTime = \trim($sTime);
|
||||
if ('-' === \substr($sTime, 0, 1))
|
||||
{
|
||||
$iMod = -1;
|
||||
$sTime = \substr($sTime, 1);
|
||||
}
|
||||
|
||||
$aParts = \preg_split('/[:.,]/', (string) $sTime);
|
||||
|
||||
$iResult = 0;
|
||||
if (isset($aParts[0]) && \is_numeric($aParts[0]))
|
||||
{
|
||||
$iResult += 3600 * ((int) $aParts[0]);
|
||||
}
|
||||
|
||||
if (isset($aParts[1]) && \is_numeric($aParts[1]))
|
||||
{
|
||||
$iResult += 60 * ((int) $aParts[1]);
|
||||
}
|
||||
|
||||
return $iResult * $iMod;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -38,9 +38,9 @@ abstract class Driver
|
|||
protected $bGuidPrefix;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
* @var DateTimeZone
|
||||
*/
|
||||
protected $sTimeOffset;
|
||||
protected $oTimeZone;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
|
|
@ -91,7 +91,7 @@ abstract class Driver
|
|||
$this->bTypedPrefix = true;
|
||||
$this->bGuidPrefix = true;
|
||||
|
||||
$this->sTimeOffset = '0';
|
||||
$this->oTimeZone = new \DateTimeZone('UTC');
|
||||
|
||||
$this->iWriteOnTimeoutOnly = 0;
|
||||
$this->bWriteOnErrorOnly = false;
|
||||
|
|
@ -116,9 +116,13 @@ abstract class Driver
|
|||
);
|
||||
}
|
||||
|
||||
public function SetTimeOffset(string $sTimeOffset) : self
|
||||
public function SetTimeZone(/*\DateTimeZone | string*/ $oTimeZone) : self
|
||||
{
|
||||
$this->sTimeOffset = (string) $sTimeOffset;
|
||||
if ($oTimeZone instanceof \DateTimeZone) {
|
||||
$this->oTimeZone = $oTimeZone;
|
||||
} else {
|
||||
$this->oTimeZone = new \DateTimeZone($oTimeZone);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
|
@ -187,9 +191,7 @@ abstract class Driver
|
|||
|
||||
protected function getTimeWithMicroSec() : string
|
||||
{
|
||||
$aMicroTimeItems = \explode(' ', \microtime());
|
||||
return Logger::DateHelper($this->sDatePattern, $this->sTimeOffset, $aMicroTimeItems[1]).'.'.
|
||||
\str_pad((int) ($aMicroTimeItems[0] * 1000), 3, '0', STR_PAD_LEFT);
|
||||
return \substr((new \DateTime('now', $this->DateTimeZone))->format('Y-m-d H:i:s.u'), 0, -3);
|
||||
}
|
||||
|
||||
protected function getTypedPrefix(int $iType, string $sName = '') : string
|
||||
|
|
|
|||
|
|
@ -74,12 +74,6 @@ class Logger extends \MailSo\Base\Collection
|
|||
return $oInstance;
|
||||
}
|
||||
|
||||
public static function DateHelper(string $sFormat, string $sTimeOffset = '0', int $iTimestamp = null) : string
|
||||
{
|
||||
$iTimestamp = null === $iTimestamp ? \time() : (int) $iTimestamp;
|
||||
return \gmdate($sFormat, $iTimestamp + \MailSo\Base\DateTimeHelper::TimeToSec((string) $sTimeOffset));
|
||||
}
|
||||
|
||||
public static function IsSystemEnabled() : bool
|
||||
{
|
||||
return !!(\MailSo\Config::$SystemLogger instanceof Logger);
|
||||
|
|
|
|||
|
|
@ -356,9 +356,9 @@ class Actions
|
|||
$aClear = array();
|
||||
|
||||
if (false !== \strpos($sLine, '{date:')) {
|
||||
$sTimeOffset = (string)$this->Config()->Get('logs', 'time_offset', '0');
|
||||
$sLine = \preg_replace_callback('/\{date:([^}]+)\}/', function ($aMatch) use ($sTimeOffset, $bUrlEncode) {
|
||||
return Utils::UrlEncode(\MailSo\Log\Logger::DateHelper($aMatch[1], $sTimeOffset), $bUrlEncode);
|
||||
$oConfig = $this->Config();
|
||||
$sLine = \preg_replace_callback('/\{date:([^}]+)\}/', function ($aMatch) use ($oConfig, $bUrlEncode) {
|
||||
return Utils::UrlEncode((new \DateTime('now', new \DateTimeZone($oConfig->Get('logs', 'time_zone', 'UTC'))))->format($aMatch[1]), $bUrlEncode);
|
||||
}, $sLine);
|
||||
|
||||
$aClear['/\{date:([^}]*)\}/'] = 'date';
|
||||
|
|
@ -761,7 +761,7 @@ class Actions
|
|||
}
|
||||
}
|
||||
|
||||
$sTimeOffset = (string)$this->Config()->Get('logs', 'time_offset', '0');
|
||||
$sTimeZone = $this->Config()->Get('logs', 'time_zone', 'UTC');
|
||||
|
||||
$this->oLogger->SetShowSecter(!$this->Config()->Get('logs', 'hide_passwords', true));
|
||||
|
||||
|
|
@ -785,7 +785,7 @@ class Actions
|
|||
->WriteOnErrorOnly($this->Config()->Get('logs', 'write_on_error_only', false))
|
||||
->WriteOnPhpErrorOnly($this->Config()->Get('logs', 'write_on_php_error_only', false))
|
||||
->WriteOnTimeoutOnly($this->Config()->Get('logs', 'write_on_timeout_only', 0))
|
||||
->SetTimeOffset($sTimeOffset)
|
||||
->SetTimeZone($sTimeZone)
|
||||
);
|
||||
|
||||
if (!$this->Config()->Get('debug', 'enable', false)) {
|
||||
|
|
@ -796,9 +796,8 @@ class Actions
|
|||
|
||||
$oHttp = $this->Http();
|
||||
|
||||
$this->oLogger->Write('[DATE:' . \MailSo\Log\Logger::DateHelper('d.m.y', $sTimeOffset) .
|
||||
(0 !== $sTimeOffset ? '][OFFSET:' . (0 < $sTimeOffset ? '+' : '-') .
|
||||
\str_pad((string)\abs($sTimeOffset), 2, '0', STR_PAD_LEFT) : '') .
|
||||
$this->oLogger->Write('[DATE:' . (new \DateTime('now', new \DateTimeZone($sTimeZone)))->format('Y-m-d ') .
|
||||
$sTimeZone .
|
||||
'][RL:' . APP_VERSION . '][PHP:' . PHP_VERSION . '][IP:' .
|
||||
$oHttp->GetClientIp($this->Config()->Get('labs', 'http_client_ip_check_proxy', false)) . '][PID:' .
|
||||
(\MailSo\Base\Utils::FunctionExistsAndEnabled('getmypid') ? \getmypid() : 'unknown') . '][' .
|
||||
|
|
|
|||
|
|
@ -251,7 +251,7 @@ Values:
|
|||
'hide_passwords' => array(true, 'Required for development purposes only.
|
||||
Disabling this option is not recommended.'),
|
||||
|
||||
'time_offset' => array('0'),
|
||||
'time_zone' => array('UTC'),
|
||||
'session_filter' => array(''),
|
||||
|
||||
'filename' => array('log-{date:Y-m-d}.txt',
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue