mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-31 09:06:17 +00:00
Added userOffset check to timeAgoInWords, tests added. Closes #5068.
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@7333 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
a98cafcfbe
commit
5ec8eef6ce
2 changed files with 14 additions and 7 deletions
|
@ -313,13 +313,16 @@ class TimeHelper extends AppHelper {
|
|||
if (is_array($options) && isset($options['userOffset'])) {
|
||||
$userOffset = $options['userOffset'];
|
||||
}
|
||||
$now = time();
|
||||
if (!is_null($userOffset)) {
|
||||
$now = $this->convert(time(), $userOffset);
|
||||
}
|
||||
$in_seconds = $this->fromString($dateTime, $userOffset);
|
||||
$backwards = ($in_seconds > time());
|
||||
$backwards = ($in_seconds > $now);
|
||||
|
||||
$format = 'j/n/y';
|
||||
$end = '+1 month';
|
||||
$now = time();
|
||||
|
||||
|
||||
if (is_array($options)) {
|
||||
if (isset($options['format'])) {
|
||||
$format = $options['format'];
|
||||
|
@ -476,8 +479,8 @@ class TimeHelper extends AppHelper {
|
|||
* Returns true if specified datetime was within the interval specified, else false.
|
||||
*
|
||||
* @param mixed $timeInterval the numeric value with space then time type. Example of valid types: 6 hours, 2 days, 1 minute.
|
||||
* @param int $userOffset User's offset from GMT (in hours)
|
||||
* @param mixed $dateString the datestring or unix timestamp to compare
|
||||
* @param int $userOffset User's offset from GMT (in hours)
|
||||
* @return bool
|
||||
*/
|
||||
function wasWithinLast($timeInterval, $dateString, $userOffset = null) {
|
||||
|
@ -521,6 +524,7 @@ class TimeHelper extends AppHelper {
|
|||
/**
|
||||
* Returns a UNIX timestamp, given either a UNIX timestamp or a valid strtotime() date string.
|
||||
*
|
||||
* @param string $format date format string. defaults to 'd-m-Y'
|
||||
* @param string $dateString Datetime string
|
||||
* @param boolean $invalid flag to ignore results of fromString == false
|
||||
* @param int $userOffset User's offset from GMT (in hours)
|
||||
|
|
|
@ -29,11 +29,10 @@
|
|||
if (!defined('CAKEPHP_UNIT_TEST_EXECUTION')) {
|
||||
define('CAKEPHP_UNIT_TEST_EXECUTION', 1);
|
||||
}
|
||||
|
||||
uses('view'.DS.'helpers'.DS.'app_helper', 'controller'.DS.'controller', 'model'.DS.'model', 'view'.DS.'helper', 'view'.DS.'helpers'.DS.'time');
|
||||
App::import('Helper', 'Time');
|
||||
|
||||
/**
|
||||
* Short description for class.
|
||||
* Time Test Case
|
||||
*
|
||||
* @package cake.tests
|
||||
* @subpackage cake.tests.cases.libs.view.helpers
|
||||
|
@ -267,6 +266,10 @@ class TimeTest extends UnitTestCase {
|
|||
|
||||
$result = $this->Time->timeAgoInWords(strtotime('-13 months, -5 days'), array('end' => '2 years'));
|
||||
$this->assertEqual($result, '1 year, 1 month, 5 days ago');
|
||||
|
||||
$fourHours = $this->Time->timeAgoInWords(strtotime('-5 days, -2 hours'), array('userOffset' => -4));
|
||||
$result = $this->Time->timeAgoInWords(strtotime('-5 days, -2 hours'), array('userOffset' => 4));
|
||||
$this->assertEqual($fourHours, $result);
|
||||
}
|
||||
/**
|
||||
* testRelative method
|
||||
|
|
Loading…
Add table
Reference in a new issue