Feature #87935

Use $_SERVER['REQUEST_TIME'] instead of time() for the current time in viewhelper f:date.format()

Added by Dieter Porth 6 months ago. Updated 4 months ago.

Status:
Closed
Priority:
Should have
Assignee:
-
Category:
-
Target version:
-
Start date:
2019-03-16
Due date:
% Done:

100%

PHP Version:
Tags:
Complexity:
Sprint Focus:

Description

The Viewhelper f:date.format() use the time()-function, of PHP to get the current time.

$base = $arguments['base'] ?? time();

This line should be replaced by

$base = $arguments['base'] ?? $_SERVER['REQUEST_TIME'];

Reason:
$_SERVER['REQUEST_TIME'] contains the starttime of the request. Every call of a Dateviewhelper will use the same 'current time'.
If a user request a website at near midnight, two calls of time() can worstly generate two different dates with the f:format.date() viewhelper.

http://php.net/manual/en/function.time.php


Related issues

Related to TYPO3 Core - Bug #82491: FluidStyledContent Header/Date.html Partial should respect config.locale_all typoscript setting for date format frontend output New 2017-09-15

Associated revisions

Revision 8c26d46e (diff)
Added by Benni Mack 5 months ago

[BUGFIX] Fluid viewhelper f:format.date() uses timestamp from context aspect

Use timestamp from context runtime instead of use time() in
viewhelper calls to prevent different dates in rendering process.

Resolves: #87935
Releases: master, 9.5
Change-Id: I8d4f2a231746a9a4cdc280c710ae07d9499e3d3e
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/60454
Tested-by: TYPO3com <>
Tested-by: Jörg Bösche <>
Tested-by: Daniel Goerz <>
Reviewed-by: Tobi Kretschmann <>
Reviewed-by: Jörg Bösche <>
Reviewed-by: Daniel Goerz <>

Revision 053e1941 (diff)
Added by Benni Mack 5 months ago

[BUGFIX] Fluid viewhelper f:format.date() uses timestamp from context aspect

Use timestamp from context runtime instead of use time() in
viewhelper calls to prevent different dates in rendering process.

Resolves: #87935
Releases: master, 9.5
Change-Id: I8d4f2a231746a9a4cdc280c710ae07d9499e3d3e
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/60584
Tested-by: TYPO3com <>
Tested-by: Daniel Goerz <>
Reviewed-by: Daniel Goerz <>

History

#1 Updated by Georg Ringer 6 months ago

  • Status changed from New to Rejected

I opened an issue in fluid project https://github.com/TYPO3/Fluid/issues/441 and therefore closed it here

#2 Updated by Claus Due 6 months ago

  • Status changed from Rejected to New

Reopened, f:format.date is part of TYPO3 CMS so this issue was placed correctly.

#3 Updated by Markus Pircher 6 months ago

How often will this happen that a page is called just a few milliseconds before midnight?

#4 Updated by Dieter Porth 6 months ago

The Question is not, how often can this happen. The question is:
Do we want use different timestamps in views for a request?

But my idea has a disadvantage.
What will happen, if a cron-job will call a view-helper. The cronjob has no web-context. I think the correct line must be.

$base = $arguments['base'] ?? ($_SERVER['REQUEST_TIME'] ?? time());

#5 Updated by Jonas Schwabe 6 months ago

From my point of view $GLOBALS['SIM_EXEC_TIME'] should be used in TYPO3 8 and the DateTimeAspect should be used in TYPO3 9 instad of $_SERVER['REQUEST_TIME'] as it is initialized once and can be changed using the adminpanel date / time simulation feature which could actually be helpful.
Additionally this is also available when called from the command line because $GLOBALS['EXEC_TIME'] is initialized using time().

#6 Updated by Dieter Porth 6 months ago

@Jonas
Your hint is good. The argument is important to allow the change of a test-date by the adminpanel.

But the Idea got a problem. FLUID is not only part of TYPO3. Fluid is a standalone framework too. The viewhelper should not depend strictly on TYPO3.

The viewhelper may need a definition-cascade.


    if (isset($arguments['base'])) {
        $base = $arguments['base'] // Argument of the viewhelper
    } else if( class_exists(TYPO3\CMS\Core\Context\Context::class) ) {
        // if TYPO3\CMS\Core\Context\Context exist, the TYPO3-Class TYPO3\CMS\Core\Utility\ should exist.
        /** @var Context $context */
        $context = TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(TYPO3\CMS\Core\Context::class);
        $base = $context->getPropertyFromAspect('date', 'timestamp'); // TYPO3 9++
    } else if( isset($GLOBALS['SIM_EXEC_TIME']) ) {
        $base = $GLOBALS['SIM_EXEC_TIME'];  // TYPO3 8.7
    } else {
        $base = ($_SERVER['REQUEST_TIME'] ?? time());
    }

#7 Updated by Gerrit Code Review 5 months ago

  • Status changed from New to Under Review

Patch set 1 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/60454

#8 Updated by Gerrit Code Review 5 months ago

Patch set 2 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/60454

#9 Updated by Gerrit Code Review 5 months ago

Patch set 3 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/60454

#10 Updated by Gerrit Code Review 5 months ago

Patch set 4 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/60454

#11 Updated by Gerrit Code Review 5 months ago

Patch set 5 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/60454

#12 Updated by Gerrit Code Review 5 months ago

Patch set 6 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/60454

#13 Updated by Gerrit Code Review 5 months ago

Patch set 7 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/60454

#14 Updated by Gerrit Code Review 5 months ago

Patch set 8 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/60454

#15 Updated by Benni Mack 5 months ago

  • Related to Bug #82491: FluidStyledContent Header/Date.html Partial should respect config.locale_all typoscript setting for date format frontend output added

#16 Updated by Gerrit Code Review 5 months ago

Patch set 1 for branch 9.5 of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/60584

#17 Updated by Benni Mack 5 months ago

  • Status changed from Under Review to Resolved
  • % Done changed from 0 to 100

#18 Updated by Benni Mack 4 months ago

  • Status changed from Resolved to Closed

Also available in: Atom PDF