Commit b9cd1516 authored by Carsten  Rose's avatar Carsten Rose
Browse files

Merge branch 'f11957GetTimezone' into 'develop'

F11957get timezone

See merge request !308
parents edbe0a7e 5ac1bc4b
Pipeline #4980 passed with stages
in 3 minutes and 42 seconds
......@@ -185,13 +185,15 @@ The following `escape` & `action` types are available:
+-------+----------------------------------------------------------------------------------------------------------------------------------+
| L | LDAP DN values. `ldap-escape() <http://php.net/manual/en/function.ldap-escape.php>`_ (LDAP_ESCAPE_DN). |
+-------+----------------------------------------------------------------------------------------------------------------------------------+
| m | `real_escape_string() <http://php.net/manual/en/mysqli.real-escape-string.php>`_ (m = mysql) |
+-------+----------------------------------------------------------------------------------------------------------------------------------+
| p | Password hashing: depends on the hashing type in the Typo3 installation, includes salting if configured. |
+-------+----------------------------------------------------------------------------------------------------------------------------------+
| s | Single ticks ``'`` will be escaped by ``\'``. |
+-------+----------------------------------------------------------------------------------------------------------------------------------+
| S | Stop replace. If the replaced value contains nested variables, they won't be replaced. |
+-------+----------------------------------------------------------------------------------------------------------------------------------+
| m | `real_escape_string() <http://php.net/manual/en/mysqli.real-escape-string.php>`_ (m = mysql) |
+-------+----------------------------------------------------------------------------------------------------------------------------------+
| p | Password hashing: depends on the hashing type in the Typo3 installation, includes salting if configured. |
| t | Returns the central european timezone (CET / CEST) depending on the given date. If the TZ is not GMT+1 or GMT+2, returns GMT+x |
+-------+----------------------------------------------------------------------------------------------------------------------------------+
| w | wipe out current key/value pair from SIP store :ref:`variable-escape-wipe-key<variable-escape-wipe-key>` |
+-------+----------------------------------------------------------------------------------------------------------------------------------+
......
......@@ -755,6 +755,7 @@ const TOKEN_ESCAPE_MYSQL = 'm';
const TOKEN_ESCAPE_PASSWORD_T3FE = 'p';
const TOKEN_ESCAPE_NONE = '-';
const TOKEN_ESCAPE_WIPE = 'w';
const TOKEN_ESCAPE_TIMEZONE = 't';
const TOKEN_ESCAPE_STOP_REPLACE = 'S';
const TOKEN_ESCAPE_EXCEPTION = 'X';
......
......@@ -262,6 +262,32 @@ class Evaluate {
return $this->link->renderLink($token);
}
/**
* Get the CET/CEST Timezone for a given date, or if date is '' based on the current date.
*
* @param string $dateStr
* @return string // CET, CEST or GMT+?/GMT-?
*/
public function getEuropeanTimezone($dateStr = '') {
$ts = ($dateStr == '') ? time() : strtotime($dateStr);
$offset = date("Z", $ts);
$offset = date("Z", $ts) / 3600;
switch ($offset) {
case 1:
$tz = "CET";
break;
case 2:
$tz = "CEST";
break;
default:
$tz = 'GMT' . sprintf("%+d", $offset);
}
return $tz;
}
/**
* @param $arrToken
* @param $dbIndex
......@@ -437,6 +463,9 @@ class Evaluate {
case TOKEN_ESCAPE_WIPE:
$flagWipe = true;
break;
case TOKEN_ESCAPE_TIMEZONE:
$value = $this->getEuropeanTimezone($value);
break;
default:
throw new \UserFormException("Unknown escape qualifier: $escape", ERROR_UNKNOW_SANITIZE_CLASS);
break;
......
......@@ -600,6 +600,25 @@ class EvaluateTest extends AbstractDatabaseTest {
$eval->parse('go {{unknownVar:S::X}} stop');
}
/**
* @throws \CodeException
* @throws \DbException
* @throws \UserFormException
* @throws \UserReportException
*/
public function testGetEuropeanTimezone() {
$eval = new Evaluate($this->store, $this->dbArray[DB_INDEX_DEFAULT]);
date_default_timezone_set('Europe/Berlin');
$this->assertEquals('CET', $eval->getEuropeanTimezone('02.02.2020'));
$this->assertEquals('CEST', $eval->getEuropeanTimezone('02.06.2020'));
$this->assertEquals('CET', $eval->getEuropeanTimezone('02.12.2020'));
$this->assertContains($eval->getEuropeanTimezone(''), ['CET', 'CEST']);
$this->store->setVar('start', '02.06.2020', STORE_FORM, true);
$this->assertEquals('CEST', $eval->substitute('start:F:all:t', $foundInStore));
}
/**
*/
protected function setUp() {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment