Project

General

Profile

Actions

Feature #87935

closed

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

Added by Dieter Porth about 5 years ago. Updated almost 5 years ago.

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

100%

Estimated time:
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 1 (0 open1 closed)

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

Actions
Actions #1

Updated by Georg Ringer about 5 years 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

Actions #2

Updated by Claus Due about 5 years ago

  • Status changed from Rejected to New

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

Actions #3

Updated by Markus Pircher about 5 years ago

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

Actions #4

Updated by Dieter Porth about 5 years 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());

Actions #5

Updated by Jonas Schwabe almost 5 years 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().

Actions #6

Updated by Dieter Porth almost 5 years 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());
    }

Actions #7

Updated by Gerrit Code Review almost 5 years 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

Actions #8

Updated by Gerrit Code Review almost 5 years 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

Actions #9

Updated by Gerrit Code Review almost 5 years 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

Actions #10

Updated by Gerrit Code Review almost 5 years 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

Actions #11

Updated by Gerrit Code Review almost 5 years 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

Actions #12

Updated by Gerrit Code Review almost 5 years 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

Actions #13

Updated by Gerrit Code Review almost 5 years 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

Actions #14

Updated by Gerrit Code Review almost 5 years 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

Actions #15

Updated by Benni Mack almost 5 years ago

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

Updated by Gerrit Code Review almost 5 years 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

Actions #17

Updated by Benni Mack almost 5 years ago

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

Updated by Benni Mack almost 5 years ago

  • Status changed from Resolved to Closed
Actions

Also available in: Atom PDF