Feature #87935
closed
Use $_SERVER['REQUEST_TIME'] instead of time() for the current time in viewhelper f:date.format()
Added by Dieter Porth over 5 years ago.
Updated over 5 years ago.
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
- Status changed from New to Rejected
- Status changed from Rejected to New
Reopened, f:format.date is part of TYPO3 CMS so this issue was placed correctly.
How often will this happen that a page is called just a few milliseconds before midnight?
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());
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().
@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());
}
- Status changed from New to Under Review
- Related to Bug #82491: FluidStyledContent Header/Date.html Partial should respect config.locale_all typoscript setting for date format frontend output added
- Status changed from Under Review to Resolved
- % Done changed from 0 to 100
- Status changed from Resolved to Closed
Also available in: Atom
PDF