Commit 63740f31 authored by Christian Kuhn's avatar Christian Kuhn
Browse files

Revert "[TASK] Rebuild the calcAge functionality"

This change was considered to need some more work during
mrge post review:

* 6.2 version adds not allowed deprecations to a released branch
* It adds two arbitrary (public) constants CEIL and FLOOR
* Method names need improvement
* Violation of single responsibility
* The static utility class has dependencies
* The patch adds another "always loaded" file to main bootstrap
* Undocumented (minor) breaking changes
* (Minor) code style issues

Reverted: #20016
Releases: 6.3, 6.2

This reverts commit 98c0ff71
Change-Id: I7b07f2176eae78f6000db685c0f54164d5040202
Reviewed-on: https://review.typo3.org/31236
Reviewed-by: Christian Kuhn
Tested-by: Christian Kuhn
parent 869855c2
......@@ -998,15 +998,7 @@ class EditDocumentController {
)
)
) . '; return false;';
// Undo button
$buttons['undo'] = '<a href="#"
onclick="' . htmlspecialchars($aOnClick) . '"
title="' . htmlspecialchars(
sprintf(
$GLOBALS['LANG']->getLL('undoLastChange'),
\TYPO3\CMS\Core\Utility\DateTimeUtility::getAgeStringUnix($undoButtonR['tstamp'])
)
) . '">' . IconUtility::getSpriteIcon('actions-edit-undo') . '</a>';
$buttons['undo'] = '<a href="#" onclick="' . htmlspecialchars($aOnClick) . '"' . ' title="' . htmlspecialchars(sprintf($GLOBALS['LANG']->getLL('undoLastChange'), BackendUtility::calcAge(($GLOBALS['EXEC_TIME'] - $undoButtonR['tstamp']), $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:labels.minutesHoursDaysYears')))) . '">' . IconUtility::getSpriteIcon('actions-edit-undo') . '</a>';
}
if ($this->getNewIconMode($this->firstEl['table'], 'showHistory')) {
$aOnClick = 'window.location.href=' .
......
......@@ -845,6 +845,7 @@ class PageLayoutController {
$dblist->setLMargin = 0;
$dblist->doEdit = $this->EDIT_CONTENT;
$dblist->ext_CALC_PERMS = $this->CALC_PERMS;
$dblist->agePrefixes = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:labels.minutesHoursDaysYears');
$dblist->id = $this->id;
$dblist->nextThree = MathUtility::forceIntegerInRange($this->modTSconfig['properties']['editFieldsAtATime'], 0, 10);
$dblist->option_showBigButtons = $this->modTSconfig['properties']['disableBigButtons'] === '0';
......@@ -1109,12 +1110,7 @@ class PageLayoutController {
)
)
) . '; return false;') . '"
title="' . htmlspecialchars(
sprintf(
$GLOBALS['LANG']->getLL('undoLastChange'),
\TYPO3\CMS\Core\Utility\DateTimeUtility::getAgeStringUnix($this->undoButtonR['tstamp'])
)
) . '">' . IconUtility::getSpriteIcon('actions-edit-undo') . '</a>';
title="' . htmlspecialchars(sprintf($GLOBALS['LANG']->getLL('undoLastChange'), BackendUtility::calcAge(($GLOBALS['EXEC_TIME'] - $this->undoButtonR['tstamp']), $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:labels.minutesHoursDaysYears')))) . '">' . IconUtility::getSpriteIcon('actions-edit-undo') . '</a>';
// History button
$buttons['history_record'] = '<a href="#"
onclick="' . htmlspecialchars('jumpToUrl(' .
......
......@@ -243,15 +243,7 @@ class RteController {
'returnUrl' => $this->R_URI,
)
)
) . '; return false;') . '">' .
'<img' . IconUtility::skinImg($this->doc->backPath, 'gfx/undo.gif') .
' class="c-inputButton" title="' .
htmlspecialchars(
sprintf(
$GLOBALS['LANG']->getLL('rte_undoLastChange'),
\TYPO3\CMS\Core\Utility\DateTimeUtility::getAgeStringUnix($undoButtonR['tstamp'])
)
) . '" alt="" /></a>';
) . '; return false;') . '">' . '<img' . IconUtility::skinImg($this->doc->backPath, 'gfx/undo.gif') . ' class="c-inputButton" title="' . htmlspecialchars(sprintf($GLOBALS['LANG']->getLL('rte_undoLastChange'), BackendUtility::calcAge(($GLOBALS['EXEC_TIME'] - $undoButtonR['tstamp']), $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:labels.minutesHoursDaysYears')))) . '" alt="" />' . '</a>';
}
// Shortcut
if ($GLOBALS['BE_USER']->mayMakeShortcut()) {
......
......@@ -3249,7 +3249,7 @@ TBE_EDITOR.customEvalFunctions[\'' . $evalData . '\'] = function(value) {
$value = '';
}
if ($config['format.']['appendAge']) {
$value .= ' (' . \TYPO3\CMS\Core\Utility\DateTimeUtility::getAgeStringUnix($itemValue) . ')';
$value .= ' (' . BackendUtility::calcAge(($GLOBALS['EXEC_TIME'] - $itemValue), $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:labels.minutesHoursDaysYears')) . ')';
}
$itemValue = $value;
break;
......
......@@ -407,7 +407,7 @@ class RecordHistory {
// remove first link
$singleLine[] = htmlspecialchars(BackendUtility::datetime($entry['tstamp']));
// add time
$singleLine[] = htmlspecialchars(\TYPO3\CMS\Core\Utility\DateTimeUtility::getAgeStringUnix($entry['tstamp']));
$singleLine[] = htmlspecialchars(BackendUtility::calcAge($GLOBALS['EXEC_TIME'] - $entry['tstamp'], $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:labels.minutesHoursDaysYears')));
// add age
$singleLine[] = htmlspecialchars($userName);
// add user name
......
......@@ -726,12 +726,9 @@ function jumpToUrl(URL) {
*/
public function parseTime() {
if ($this->parseTimeFlag && $GLOBALS['BE_USER']->isAdmin()) {
return '<p>(ParseTime: ' .
(\TYPO3\CMS\Core\Utility\DateTimeUtility::milliseconds() - $GLOBALS['PARSETIME_START']) . ' ms</p>' .
'<p>REQUEST_URI-length: ' . strlen(GeneralUtility::getIndpEnv('REQUEST_URI')) . ')</p>';
return '<p>(ParseTime: ' . (GeneralUtility::milliseconds() - $GLOBALS['PARSETIME_START']) . ' ms</p>
<p>REQUEST_URI-length: ' . strlen(GeneralUtility::getIndpEnv('REQUEST_URI')) . ')</p>';
}
return '';
}
/**
......
......@@ -25,7 +25,6 @@ use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\MathUtility;
use TYPO3\CMS\Core\Versioning\VersionState;
use TYPO3\CMS\Frontend\Page\PageRepository;
use TYPO3\CMS\Core\Utility\DateTimeUtility;
/**
* Standard functions available for the TYPO3 backend.
......@@ -1417,16 +1416,27 @@ class BackendUtility {
* Returns the "age" in minutes / hours / days / years of the number of $seconds inputted.
*
* @param integer $seconds Seconds could be the difference of a certain timestamp and time()
* @param string $labels Labels should be something like ' min| hrs| days| yrs| min| hour| day| year'.
* This value is typically delivered by this function call: $GLOBALS["LANG"]->sL("LLL:EXT:lang/locallang_core.xlf:labels.minutesHoursDaysYears")
*
* @param string $labels Labels should be something like ' min| hrs| days| yrs| min| hour| day| year'. This value is typically delivered by this function call: $GLOBALS["LANG"]->sL("LLL:EXT:lang/locallang_core.xlf:labels.minutesHoursDaysYears")
* @return string Formatted time
* @deprecated since 6.2, will be removed two versions later, use \TYPO3\CMS\Core\Utility\DateTimeUtility::getAgeStringUnix
* or \TYPO3\CMS\Core\Utility\DateTimeUtility::getSimpleAgeString
*/
static public function calcAge($seconds, $labels = ' min| hrs| days| yrs| min| hour| day| year') {
GeneralUtility::logDeprecatedFunction();
return DateTimeUtility::getSimpleAgeString($seconds, $labels);
$labelArr = explode('|', $labels);
$absSeconds = abs($seconds);
$sign = $seconds < 0 ? -1 : 1;
if ($absSeconds < 3600) {
$val = round($absSeconds / 60);
$seconds = $sign * $val . ($val == 1 ? $labelArr[4] : $labelArr[0]);
} elseif ($absSeconds < 24 * 3600) {
$val = round($absSeconds / 3600);
$seconds = $sign * $val . ($val == 1 ? $labelArr[5] : $labelArr[1]);
} elseif ($absSeconds < 365 * 24 * 3600) {
$val = round($absSeconds / (24 * 3600));
$seconds = $sign * $val . ($val == 1 ? $labelArr[6] : $labelArr[2]);
} else {
$val = round($absSeconds / (365 * 24 * 3600));
$seconds = $sign * $val . ($val == 1 ? $labelArr[7] : $labelArr[3]);
}
return $seconds;
}
/**
......@@ -1439,16 +1449,7 @@ class BackendUtility {
* @return string
*/
static public function dateTimeAge($tstamp, $prefix = 1, $date = '') {
if (!$tstamp) {
return '';
}
$date = $date == 'date'
? self::date($tstamp)
: self::datetime($tstamp);
$age = $prefix === 1
? DateTimeUtility::getTimeDiffStringUnix($GLOBALS['EXEC_TIME'], $tstamp)
: DateTimeUtility::getTimeDiffStringUnix($tstamp, $GLOBALS['EXEC_TIME']);
return $date . ' (' . $age . ')';
return $tstamp ? ($date == 'date' ? self::date($tstamp) : self::datetime($tstamp)) . ' (' . self::calcAge($prefix * ($GLOBALS['EXEC_TIME'] - $tstamp), $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:labels.minutesHoursDaysYears')) . ')' : '';
}
/**
......@@ -2143,7 +2144,7 @@ class BackendUtility {
$value = $value !== $emptyValue ? strtotime($value) : 0;
}
if (!empty($value)) {
$l = static::dateTimeAge($value, -1, 'date');
$l = self::date($value) . ' (' . ($GLOBALS['EXEC_TIME'] - $value > 0 ? '-' : '') . self::calcAge(abs(($GLOBALS['EXEC_TIME'] - $value)), $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:labels.minutesHoursDaysYears')) . ')';
}
} elseif (GeneralUtility::inList($theColConf['eval'], 'time')) {
if (!empty($value)) {
......@@ -3133,19 +3134,9 @@ class BackendUtility {
$userName = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:labels.unknownUser');
}
$GLOBALS['LOCKED_RECORDS'][$row['record_table'] . ':' . $row['record_uid']] = $row;
$GLOBALS['LOCKED_RECORDS'][$row['record_table'] . ':' . $row['record_uid']]['msg'] = sprintf(
$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:labels.lockedRecordUser'),
$userType,
$userName,
DateTimeUtility::getAgeStringUnix($row['tstamp'])
);
$GLOBALS['LOCKED_RECORDS'][$row['record_table'] . ':' . $row['record_uid']]['msg'] = sprintf($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:labels.lockedRecordUser'), $userType, $userName, self::calcAge($GLOBALS['EXEC_TIME'] - $row['tstamp'], $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:labels.minutesHoursDaysYears')));
if ($row['record_pid'] && !isset($GLOBALS['LOCKED_RECORDS'][($row['record_table'] . ':' . $row['record_pid'])])) {
$GLOBALS['LOCKED_RECORDS']['pages:' . $row['record_pid']]['msg'] = sprintf(
$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:labels.lockedRecordUser_content'),
$userType,
$userName,
DateTimeUtility::getAgeStringUnix($row['tstamp'])
);
$GLOBALS['LOCKED_RECORDS']['pages:' . $row['record_pid']]['msg'] = sprintf($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:labels.lockedRecordUser_content'), $userType, $userName, self::calcAge($GLOBALS['EXEC_TIME'] - $row['tstamp'], $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:labels.minutesHoursDaysYears')));
}
}
$GLOBALS['TYPO3_DB']->sql_free_result($res);
......
......@@ -75,6 +75,12 @@ class PageLayoutView extends \TYPO3\CMS\Recordlist\RecordList\AbstractDatabaseRe
*/
public $doEdit = 1;
// Age prefixes for displaying times. May be set externally to localized values.
/**
* @todo Define visibility
*/
public $agePrefixes = ' min| hrs| days| yrs| min| hour| day| year';
// Array of tables to be listed by the Web > Page module in addition to the default tables.
/**
* @todo Define visibility
......@@ -2094,7 +2100,6 @@ class PageLayoutView extends \TYPO3\CMS\Recordlist\RecordList\AbstractDatabaseRe
*
*****************************************/
/**
* Creates a menu of the tables that can be listed by this function
* Only tables which has records on the page will be included.
......
......@@ -23,6 +23,95 @@ use TYPO3\CMS\Backend\Utility\BackendUtility;
*/
class BackendUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
///////////////////////////////////////
// Tests concerning calcAge
///////////////////////////////////////
/**
* Data provider for calcAge function
*
* @return array
*/
public function calcAgeDataProvider() {
return array(
'Single year' => array(
'seconds' => 60 * 60 * 24 * 365,
'expectedLabel' => '1 year'
),
'Plural years' => array(
'seconds' => 60 * 60 * 24 * 365 * 2,
'expectedLabel' => '2 yrs'
),
'Single negative year' => array(
'seconds' => 60 * 60 * 24 * 365 * -1,
'expectedLabel' => '-1 year'
),
'Plural negative years' => array(
'seconds' => 60 * 60 * 24 * 365 * 2 * -1,
'expectedLabel' => '-2 yrs'
),
'Single day' => array(
'seconds' => 60 * 60 * 24,
'expectedLabel' => '1 day'
),
'Plural days' => array(
'seconds' => 60 * 60 * 24 * 2,
'expectedLabel' => '2 days'
),
'Single negative day' => array(
'seconds' => 60 * 60 * 24 * -1,
'expectedLabel' => '-1 day'
),
'Plural negative days' => array(
'seconds' => 60 * 60 * 24 * 2 * -1,
'expectedLabel' => '-2 days'
),
'Single hour' => array(
'seconds' => 60 * 60,
'expectedLabel' => '1 hour'
),
'Plural hours' => array(
'seconds' => 60 * 60 * 2,
'expectedLabel' => '2 hrs'
),
'Single negative hour' => array(
'seconds' => 60 * 60 * -1,
'expectedLabel' => '-1 hour'
),
'Plural negative hours' => array(
'seconds' => 60 * 60 * 2 * -1,
'expectedLabel' => '-2 hrs'
),
'Single minute' => array(
'seconds' => 60,
'expectedLabel' => '1 min'
),
'Plural minutes' => array(
'seconds' => 60 * 2,
'expectedLabel' => '2 min'
),
'Single negative minute' => array(
'seconds' => 60 * -1,
'expectedLabel' => '-1 min'
),
'Plural negative minutes' => array(
'seconds' => 60 * 2 * -1,
'expectedLabel' => '-2 min'
),
'Zero seconds' => array(
'seconds' => 0,
'expectedLabel' => '0 min'
)
);
}
/**
* @test
* @dataProvider calcAgeDataProvider
*/
public function calcAgeReturnsExpectedValues($seconds, $expectedLabel) {
$this->assertSame($expectedLabel, BackendUtility::calcAge($seconds));
}
///////////////////////////////////////
// Tests concerning getProcessedValue
///////////////////////////////////////
......
......@@ -193,7 +193,6 @@ class SystemEnvironmentBuilder {
*/
static protected function requireBaseClasses() {
require_once __DIR__ . '/../Utility/GeneralUtility.php';
require_once __DIR__ . '/../Utility/DateTimeUtility.php';
require_once __DIR__ . '/../Utility/ArrayUtility.php';
require_once __DIR__ . '/../Utility/PathUtility.php';
require_once __DIR__ . '/../SingletonInterface.php';
......@@ -268,7 +267,7 @@ class SystemEnvironmentBuilder {
*/
static protected function initializeGlobalTimeTrackingVariables() {
// Set PARSETIME_START to the system time in milliseconds.
$GLOBALS['PARSETIME_START'] = \TYPO3\CMS\Core\Utility\DateTimeUtility::milliseconds();
$GLOBALS['PARSETIME_START'] = \TYPO3\CMS\Core\Utility\GeneralUtility::milliseconds();
// Microtime of (nearly) script start
$GLOBALS['TYPO3_MISC']['microtime_start'] = microtime(TRUE);
// EXEC_TIME is set so that the rest of the script has a common value for the script execution time
......
<?php
namespace TYPO3\CMS\Core\Utility;
/***************************************************************
* Copyright notice
*
* (c) 2014 Alexander Opitz <opitz.alexander@googlemail.com>
* (c) 2014 Markus Klein <klein.t3@mfc-linz.at>
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
* A copy is found in the textfile GPL.txt and important notices to the license
* from the author is found in LICENSE.txt distributed with these scripts.
*
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
use TYPO3\CMS\Lang\LanguageService;
/**
* This class has functions for handling date and time. Especially differences between two dates as readable string.
*
* @author Alexander Opitz <opitz@pluspol.info>
* @author Markus Klein <klein.t3@mfc-linz.at>
*/
class DateTimeUtility {
/**
* @var int for usage with the getSimpleAgeString or round function
*/
const CEIL = 10;
/**
* @var int for usage with the getSimpleAgeString or round function
*/
const FLOOR = 11;
/**
* Returns the given microtime as milliseconds.
*
* @param string $microtime Microtime as "msec sec" string given by php function microtime
* @return int Microtime input string converted to an int (milliseconds)
*/
static public function convertMicrotime($microtime) {
$parts = explode(' ', $microtime);
return (int)round(($parts[0] + $parts[1]) * 1000);
}
/**
* Gets the unixtime as milliseconds.
*
* @return int The unixtime as milliseconds
*/
static public function milliseconds() {
return (int)round(microtime(TRUE) * 1000);
}
/**
* Returns a string representation of the difference between timestamps in minutes / hours / days / months / years
* with a given label.
*
* @param int $startTime Unix timestamp for calculating difference of
* @param int $endTime Unix timestamp for calculating difference to
* @param string|array|NULL $labels Labels should be something like ' mins| hrs| days| months| yrs| min| hour| day| month| year'
* This value is typically delivered by this function call:
* $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:labels.minutesHoursDaysMonthsYears')
* Or using the array returned by splitTimeUnitsFromLabel()
* @return string Formatted time difference
*/
static public function getTimeDiffStringUnix($startTime, $endTime, $labels = NULL) {
return static::getTimeDiffString(
new \DateTime('@' . $startTime),
new \DateTime('@' . $endTime),
$labels
);
}
/**
* Returns a string representation of the difference between DateTimes in minutes / hours / days / months / years
* with a given label.
*
* @param \DateTime $startDateTime Unix timestamp for calculating difference of
* @param \DateTime $endDateTime Unix timestamp for calculating difference to
* @param string|array|NULL $labels Labels should be something like ' mins| hrs| days| months| yrs| min| hour| day| month| year'
* This value is typically delivered by this function call:
* $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:labels.minutesHoursDaysMonthsYears')
* Or using the array returned by splitTimeUnitsFromLabel()
* @return string Formatted time difference
*/
static public function getTimeDiffString(\DateTime $startDateTime, \DateTime $endDateTime, $labels = NULL) {
if (!is_array($labels) || empty($labels)) {
$labels = static::splitTimeUnitsFromLabel($labels);
}
$dateDiff = $startDateTime->diff($endDateTime);
if ($dateDiff->y > 0) {
$value = $dateDiff->y;
$label = 'year';
} elseif ($dateDiff->m > 0 && isset($labels['months'])) {
$value = $dateDiff->m;
$label = 'month';
} elseif ($dateDiff->days > 0) {
$value = $dateDiff->days;
$label = 'day';
} elseif ($dateDiff->h > 0) {
$value = $dateDiff->h;
$label = 'hour';
} else {
$value = $dateDiff->i;
$label = 'min';
}
// Get real label depending on singular/plural
$label = $labels[$label . ($value === 1 ? '' : 's')];
if ($dateDiff->invert === 1) {
$value *= -1;
}
return $value . $label;
}
/**
* Converts the old plural, old singular/plural and the new singular/plural pipe split string
* into an array with known unit names as keys.
*
* @param string|NULL $labels Labels should be something like ' min| hrs| days| months| yrs| min| hour| day| month| year'
* This value is typically delivered by this function call:
* $GLOBALS['LANG']->sL("LLL:EXT:lang/locallang_core.xlf:labels.minutesHoursDaysMonthsYears")
* @return array String split array
*/
static public function splitTimeUnitsFromLabel($labels = NULL) {
if (NULL === $labels) {
$lang = self::getLanguageService();
$tsfe = self::getTypoScriptFrontendController();
if ($lang) {
$labels = $lang->sL('LLL:EXT:lang/locallang_core.xlf:labels.minutesHoursDaysMonthsYears');
} elseif ($tsfe) {
$labels = $tsfe->sL('LLL:EXT:lang/locallang_core.xlf:labels.minutesHoursDaysMonthsYears');
}
// Couldn't determine from local config so take default value.
if (empty($labels)) {
$labels = ' min| hrs| days| months| yrs| min| hour| day| month| year';
}
} else {
$labels = str_replace('"', '', $labels);
}
$labelArr = explode('|', $labels);
$resultArr = array();
if (count($labelArr) === 4) {
// Old plural labels string, add plural as singular
$labelArr = array_merge($labelArr, $labelArr);
}
switch (count($labelArr)) {
case 8:
// Old singular and plural labels string
$resultArr['min'] = $labelArr[4];
$resultArr['mins'] = $labelArr[0];
$resultArr['hour'] = $labelArr[5];
$resultArr['hours'] = $labelArr[1];
$resultArr['day'] = $labelArr[6];
$resultArr['days'] = $labelArr[2];
$resultArr['year'] = $labelArr[7];
$resultArr['years'] = $labelArr[3];
break;
case 10:
// New singular and plural labels string (with month)
$resultArr['min'] = $labelArr[5];
$resultArr['mins'] = $labelArr[0];
$resultArr['hour'] = $labelArr[6];
$resultArr['hours'] = $labelArr[1];
$resultArr['day'] = $labelArr[7];
$resultArr['days'] = $labelArr[2];
$resultArr['month'] = $labelArr[8];
$resultArr['months'] = $labelArr[3];
$resultArr['year'] = $labelArr[9];
$resultArr['years'] = $labelArr[4];
break;
default:
static::splitTimeUnitsFromLabel(NULL);
}
return $resultArr;
}
/**
* Returns the "age" in minutes / hours / days / months / years depending of the number of $seconds inputted.
*
* @param int $seconds Seconds could be the difference of a certain timestamp and time()
* @param string|array|NULL $labels Labels should be something like ' min| hrs| days| months| yrs| min| hour| day| month| year'
* This value is typically delivered by this function call:
* $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:labels.minutesHoursDaysMonthsYears')
* Or using the array returned by splitTimeUnitsFromLabel()
* @param int $method Method to use to round the result (PHP_ROUND_HALF_UP, PHP_ROUND_HALF_DOWN,
* PHP_ROUND_HALF_EVEN, PHP_ROUND_HALF_ODD - round, 10 - ceil, 11 - floor)
* @return string Formatted time
*/
static public function getSimpleAgeString($seconds, $labels = NULL, $method = PHP_ROUND_HALF_UP) {
if (!is_array($labels) || empty($labels)) {
$labels = static::splitTimeUnitsFromLabel($labels);
}
$sign = $seconds < 0 ? -1 : 1;
$seconds = abs($seconds);
if ($seconds < 3600) {
$roundedResult = static::round($seconds / 60, $method);
$seconds = $sign * $roundedResult . ($roundedResult == 1 ? $labels['mins'] : $labels['min']);
} elseif ($seconds < 24 * 3600) {
$roundedResult = static::round($seconds / 3600, $method);
$seconds = $sign * $roundedResult . ($roundedResult == 1 ? $labels['hour'] : $labels['hours']);
} elseif ($seconds < 30 * 24 * 3600 || (!isset($labels['month']) && $seconds < 365 * 24 * 3600)) {
$roundedResult = static::round($seconds / (24 * 3600), $method);
$seconds = $sign * $roundedResult . ($roundedResult == 1 ? $labels['day'] : $labels['days']);
} elseif (isset($labels['month']) && $seconds < 365 * 24 * 3600) {
$roundedResult = static::round($seconds / (30 * 24 * 3600), $method);
$seconds = $sign * $roundedResult . ($roundedResult == 1 ? $labels['month'] : $labels['months']);
} else {
$roundedResult = static::round($seconds / (365 * 24 * 3600), $method);
$seconds = $sign * $roundedResult . ($roundedResult == 1 ? $labels['year'] : $labels['years']);
}
return $seconds;
}
/**
* Returns a string representation of the age of a timestamps in minutes / hours / days / months / years
* with a given label. $GLOBALS['EXEC_TIME'] is taken as "now".
*
* @param int $time Unix timestamp for calculating age of
* @param string|array|NULL $labels Labels should be something like ' min| hrs| days| months| yrs| min| hour| day| month| year'
* This value is typically delivered by this function call: