mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-08-25 10:09:20 +03:00
Fix time_offset setting (#1241)
This commit is contained in:
parent
7e135b10ac
commit
022ed24c2a
6 changed files with 1345 additions and 1310 deletions
|
|
@ -120,4 +120,35 @@ class DateTimeHelper
|
|||
|
||||
return \MailSo\Base\DateTimeHelper::ParseDateStringType1($sDateTime);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sTime
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public static function TimeToSec($sTime)
|
||||
{
|
||||
$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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37,6 +37,11 @@ abstract class Driver
|
|||
*/
|
||||
protected $bGuidPrefix;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $sTimeOffset;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
|
|
@ -89,7 +94,7 @@ abstract class Driver
|
|||
$this->bTypedPrefix = true;
|
||||
$this->bGuidPrefix = true;
|
||||
|
||||
$this->iTimeOffset = 0;
|
||||
$this->sTimeOffset = '0';
|
||||
|
||||
$this->iWriteOnTimeoutOnly = 0;
|
||||
$this->bWriteOnErrorOnly = false;
|
||||
|
|
@ -115,13 +120,13 @@ abstract class Driver
|
|||
}
|
||||
|
||||
/**
|
||||
* @param int $iTimeOffset
|
||||
* @param string $sTimeOffset
|
||||
*
|
||||
* @return \MailSo\Log\Driver
|
||||
*/
|
||||
public function SetTimeOffset($iTimeOffset)
|
||||
public function SetTimeOffset($sTimeOffset)
|
||||
{
|
||||
$this->iTimeOffset = $iTimeOffset;
|
||||
$this->sTimeOffset = (string) $sTimeOffset;
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
|
@ -236,7 +241,7 @@ abstract class Driver
|
|||
protected function getTimeWithMicroSec()
|
||||
{
|
||||
$aMicroTimeItems = \explode(' ', \microtime());
|
||||
return \MailSo\Log\Logger::DateHelper($this->sDatePattern, $this->iTimeOffset, $aMicroTimeItems[1]).'.'.
|
||||
return \MailSo\Log\Logger::DateHelper($this->sDatePattern, $this->sTimeOffset, $aMicroTimeItems[1]).'.'.
|
||||
\str_pad((int) ($aMicroTimeItems[0] * 1000), 3, '0', STR_PAD_LEFT);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -93,17 +93,15 @@ class Logger extends \MailSo\Base\Collection
|
|||
|
||||
/**
|
||||
* @param string $sFormat
|
||||
* @param int $iTimeOffset = 0
|
||||
* @param string $sTimeOffset = '0'
|
||||
* @param int $iTimestamp = 0
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function DateHelper($sFormat, $iTimeOffset = 0, $iTimestamp = null)
|
||||
public static function DateHelper($sFormat, $sTimeOffset = '0', $iTimestamp = null)
|
||||
{
|
||||
$iTimestamp = null === $iTimestamp ? \time() : (int) $iTimestamp;
|
||||
$iTimeOffset = (int) $iTimeOffset;
|
||||
|
||||
return \gmdate($sFormat, $iTimestamp + $iTimeOffset * 3600);
|
||||
return \gmdate($sFormat, $iTimestamp + \MailSo\Base\DateTimeHelper::TimeToSec((string) $sTimeOffset));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -430,9 +430,9 @@ class Actions
|
|||
|
||||
if (false !== \strpos($sLine, '{date:'))
|
||||
{
|
||||
$iTimeOffset = (int) $this->Config()->Get('logs', 'time_offset', 0);
|
||||
$sLine = \preg_replace_callback('/\{date:([^}]+)\}/', function ($aMatch) use ($iTimeOffset, $bUrlEncode) {
|
||||
return \RainLoop\Utils::UrlEncode(\MailSo\Log\Logger::DateHelper($aMatch[1], $iTimeOffset), $bUrlEncode);
|
||||
$sTimeOffset = (string) $this->Config()->Get('logs', 'time_offset', '0');
|
||||
$sLine = \preg_replace_callback('/\{date:([^}]+)\}/', function ($aMatch) use ($sTimeOffset, $bUrlEncode) {
|
||||
return \RainLoop\Utils::UrlEncode(\MailSo\Log\Logger::DateHelper($aMatch[1], $sTimeOffset), $bUrlEncode);
|
||||
}, $sLine);
|
||||
|
||||
$aClear['/\{date:([^}]*)\}/'] = 'date';
|
||||
|
|
@ -1073,7 +1073,7 @@ class Actions
|
|||
}
|
||||
}
|
||||
|
||||
$iTimeOffset = (int) $this->Config()->Get('logs', 'time_offset', 0);
|
||||
$sTimeOffset = (string) $this->Config()->Get('logs', 'time_offset', '0');
|
||||
|
||||
$this->oLogger->SetShowSecter(!$this->Config()->Get('logs', 'hide_passwords', true));
|
||||
|
||||
|
|
@ -1101,7 +1101,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($iTimeOffset)
|
||||
->SetTimeOffset($sTimeOffset)
|
||||
);
|
||||
|
||||
if (!$this->Config()->Get('debug', 'enable', false))
|
||||
|
|
@ -1113,9 +1113,9 @@ class Actions
|
|||
|
||||
$oHttp = $this->Http();
|
||||
|
||||
$this->oLogger->Write('[DATE:'.\MailSo\Log\Logger::DateHelper('d.m.y', $iTimeOffset).
|
||||
(0 !== $iTimeOffset ? '][OFFSET:'.(0 < $iTimeOffset ? '+' : '-').
|
||||
\str_pad((string) \abs($iTimeOffset), 2, '0', STR_PAD_LEFT) : '').
|
||||
$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) : '').
|
||||
'][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').']['.
|
||||
|
|
|
|||
|
|
@ -97,6 +97,7 @@ abstract class AbstractConfig
|
|||
switch ($sType)
|
||||
{
|
||||
default:
|
||||
case 'float':
|
||||
case 'string':
|
||||
$this->aData[$sSectionKey][$sParamKey][0] = (string) $mParamValue;
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -293,7 +293,7 @@ Values:
|
|||
'hide_passwords' => array(true, 'Required for development purposes only.
|
||||
Disabling this option is not recommended.'),
|
||||
|
||||
'time_offset' => array(0),
|
||||
'time_offset' => array('0'),
|
||||
'session_filter' => array(''),
|
||||
|
||||
'filename' => array('log-{date:Y-m-d}.txt',
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue