Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
typo3
qfq
Commits
1106f323
Commit
1106f323
authored
Feb 07, 2021
by
Carsten Rose
Browse files
Fixes #11957: Get European Timezone {{start:R::t}}
parent
edbe0a7e
Pipeline
#4978
passed with stages
in 3 minutes and 56 seconds
Changes
4
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Documentation/Variable.rst
View file @
1106f323
...
...
@@ -193,6 +193,8 @@ The following `escape` & `action` types are available:
+-------+----------------------------------------------------------------------------------------------------------------------------------+
| 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>` |
+-------+----------------------------------------------------------------------------------------------------------------------------------+
| X | Throw exception if variable is not found in the given store(s). Outputs :ref:`variable-type-message-violate` |
...
...
extension/Classes/Core/Constants.php
View file @
1106f323
...
...
@@ -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'
;
...
...
extension/Classes/Core/Evaluate.php
View file @
1106f323
...
...
@@ -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
;
...
...
extension/Tests/Unit/Core/EvaluateTest.php
View file @
1106f323
...
...
@@ -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
()
{
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment