mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Revert changes in behavior made to timeAgoInWords()
Changes made in [0729aca706
] changed
the generated text to not match the behavior in 2.1.
This commit is contained in:
parent
eb7b66b37c
commit
3f78216e96
2 changed files with 70 additions and 63 deletions
|
@ -96,10 +96,10 @@ class CakeTimeTest extends CakeTestCase {
|
||||||
*/
|
*/
|
||||||
public function testTimeAgoInWords() {
|
public function testTimeAgoInWords() {
|
||||||
$result = $this->Time->timeAgoInWords('-1 week');
|
$result = $this->Time->timeAgoInWords('-1 week');
|
||||||
$this->assertEquals(date('l d/m, H:i', strtotime('-1 week')), $result);
|
$this->assertEquals('1 week ago', $result);
|
||||||
|
|
||||||
$result = $this->Time->timeAgoInWords('+1 week');
|
$result = $this->Time->timeAgoInWords('+1 week');
|
||||||
$this->assertEquals('On ' . date('l d/m, H:i', strtotime('+1 week')), $result);
|
$this->assertEquals('1 week', $result);
|
||||||
|
|
||||||
$result = $this->Time->timeAgoInWords(
|
$result = $this->Time->timeAgoInWords(
|
||||||
strtotime('+4 months +2 weeks +3 days'),
|
strtotime('+4 months +2 weeks +3 days'),
|
||||||
|
@ -155,20 +155,6 @@ class CakeTimeTest extends CakeTestCase {
|
||||||
);
|
);
|
||||||
$this->assertEquals('2 months, 1 week, 6 days', $result);
|
$this->assertEquals('2 months, 1 week, 6 days', $result);
|
||||||
|
|
||||||
$result = $this->Time->timeAgoInWords(
|
|
||||||
strtotime('-1 month -1 week -6 days'),
|
|
||||||
array('end' => '1 year', 'accuracy' => array('month' => 'month'))
|
|
||||||
);
|
|
||||||
$this->assertEquals('1 month ago', $result);
|
|
||||||
|
|
||||||
$timestamp = strtotime('-1 years -2 weeks -3 days');
|
|
||||||
$result = $this->Time->timeAgoInWords(
|
|
||||||
$timestamp,
|
|
||||||
array('accuracy' => array('year' => 'year'))
|
|
||||||
);
|
|
||||||
$expected = 'on ' . date('j/n/y', $timestamp);
|
|
||||||
$this->assertEquals($expected, $result);
|
|
||||||
|
|
||||||
$result = $this->Time->timeAgoInWords(
|
$result = $this->Time->timeAgoInWords(
|
||||||
strtotime('+8 years +4 months +2 weeks +3 days'),
|
strtotime('+8 years +4 months +2 weeks +3 days'),
|
||||||
array('accuracy' => array('year' => 'year'), 'end' => '+10 years')
|
array('accuracy' => array('year' => 'year'), 'end' => '+10 years')
|
||||||
|
@ -204,25 +190,8 @@ class CakeTimeTest extends CakeTestCase {
|
||||||
$expected = '1 year';
|
$expected = '1 year';
|
||||||
$this->assertEquals($expected, $result);
|
$this->assertEquals($expected, $result);
|
||||||
|
|
||||||
for ($i = 0; $i > -200; $i--) {
|
$result = $this->Time->timeAgoInWords(time());
|
||||||
$seconds = round($i + ($i * $i));
|
$this->assertEquals('just now', $result);
|
||||||
$time = strtotime('+' . $seconds . ' seconds');
|
|
||||||
$result = $this->Time->timeAgoInWords($time);
|
|
||||||
|
|
||||||
if ($time == time()) {
|
|
||||||
$expected = 'just now';
|
|
||||||
$this->assertEquals($expected, $result);
|
|
||||||
} elseif (date("Y-m-d", $time) == date("Y-m-d")) {
|
|
||||||
$expected = 'Today, ' . date("H:i", $time);
|
|
||||||
$this->assertEquals($expected, $result);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$result = $this->Time->timeAgoInWords(
|
|
||||||
strtotime('-2 years -5 months -2 days'),
|
|
||||||
array('end' => '3 years')
|
|
||||||
);
|
|
||||||
$this->assertEquals('2 years, 5 months, 2 days ago', $result);
|
|
||||||
|
|
||||||
$result = $this->Time->timeAgoInWords('2007-9-25');
|
$result = $this->Time->timeAgoInWords('2007-9-25');
|
||||||
$this->assertEquals('on 25/9/07', $result);
|
$this->assertEquals('on 25/9/07', $result);
|
||||||
|
@ -233,12 +202,6 @@ class CakeTimeTest extends CakeTestCase {
|
||||||
$result = $this->Time->timeAgoInWords('2007-9-25', 'Y-m-d');
|
$result = $this->Time->timeAgoInWords('2007-9-25', 'Y-m-d');
|
||||||
$this->assertEquals('on 2007-09-25', $result);
|
$this->assertEquals('on 2007-09-25', $result);
|
||||||
|
|
||||||
$result = $this->Time->timeAgoInWords(
|
|
||||||
strtotime('-2 weeks -2 days'),
|
|
||||||
'Y-m-d'
|
|
||||||
);
|
|
||||||
$this->assertEquals('2 weeks, 2 days ago', $result);
|
|
||||||
|
|
||||||
$result = $this->Time->timeAgoInWords(
|
$result = $this->Time->timeAgoInWords(
|
||||||
strtotime('+2 weeks +2 days'),
|
strtotime('+2 weeks +2 days'),
|
||||||
'Y-m-d'
|
'Y-m-d'
|
||||||
|
@ -272,18 +235,6 @@ class CakeTimeTest extends CakeTestCase {
|
||||||
);
|
);
|
||||||
$this->assertEquals('3 months, 5 days', $result);
|
$this->assertEquals('3 months, 5 days', $result);
|
||||||
|
|
||||||
$result = $this->Time->timeAgoInWords(
|
|
||||||
strtotime('-2 months -2 days'),
|
|
||||||
array('end' => '3 month')
|
|
||||||
);
|
|
||||||
$this->assertEquals('2 months, 2 days ago', $result);
|
|
||||||
|
|
||||||
$result = $this->Time->timeAgoInWords(
|
|
||||||
strtotime('-2 months -2 days'),
|
|
||||||
array('end' => '3 month')
|
|
||||||
);
|
|
||||||
$this->assertEquals('2 months, 2 days ago', $result);
|
|
||||||
|
|
||||||
$result = $this->Time->timeAgoInWords(
|
$result = $this->Time->timeAgoInWords(
|
||||||
strtotime('+2 months +2 days'),
|
strtotime('+2 months +2 days'),
|
||||||
array('end' => '3 month')
|
array('end' => '3 month')
|
||||||
|
@ -295,6 +246,25 @@ class CakeTimeTest extends CakeTestCase {
|
||||||
array('end' => '1 month', 'format' => 'Y-m-d')
|
array('end' => '1 month', 'format' => 'Y-m-d')
|
||||||
);
|
);
|
||||||
$this->assertEquals('on ' . date('Y-m-d', strtotime('+2 months +2 days')), $result);
|
$this->assertEquals('on ' . date('Y-m-d', strtotime('+2 months +2 days')), $result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* test timeAgoInWords() with negative values.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testTimeAgoInWordsNegativeValues() {
|
||||||
|
$result = $this->Time->timeAgoInWords(
|
||||||
|
strtotime('-2 months -2 days'),
|
||||||
|
array('end' => '3 month')
|
||||||
|
);
|
||||||
|
$this->assertEquals('2 months, 2 days ago', $result);
|
||||||
|
|
||||||
|
$result = $this->Time->timeAgoInWords(
|
||||||
|
strtotime('-2 months -2 days'),
|
||||||
|
array('end' => '3 month')
|
||||||
|
);
|
||||||
|
$this->assertEquals('2 months, 2 days ago', $result);
|
||||||
|
|
||||||
$result = $this->Time->timeAgoInWords(
|
$result = $this->Time->timeAgoInWords(
|
||||||
strtotime('-2 months -2 days'),
|
strtotime('-2 months -2 days'),
|
||||||
|
@ -302,11 +272,54 @@ class CakeTimeTest extends CakeTestCase {
|
||||||
);
|
);
|
||||||
$this->assertEquals('on ' . date('Y-m-d', strtotime('-2 months -2 days')), $result);
|
$this->assertEquals('on ' . date('Y-m-d', strtotime('-2 months -2 days')), $result);
|
||||||
|
|
||||||
|
$result = $this->Time->timeAgoInWords(
|
||||||
|
strtotime('-2 years -5 months -2 days'),
|
||||||
|
array('end' => '3 years')
|
||||||
|
);
|
||||||
|
$this->assertEquals('2 years, 5 months, 2 days ago', $result);
|
||||||
|
|
||||||
|
$result = $this->Time->timeAgoInWords(
|
||||||
|
strtotime('-2 weeks -2 days'),
|
||||||
|
'Y-m-d'
|
||||||
|
);
|
||||||
|
$this->assertEquals('2 weeks, 2 days ago', $result);
|
||||||
|
|
||||||
|
$time = strtotime('-3 years -12 months');
|
||||||
|
$result = $this->Time->timeAgoInWords($time);
|
||||||
|
$expected = 'on ' . date('j/n/y', $time);
|
||||||
|
$this->assertEquals($expected, $result);
|
||||||
|
|
||||||
|
$result = $this->Time->timeAgoInWords(
|
||||||
|
strtotime('-1 month -1 week -6 days'),
|
||||||
|
array('end' => '1 year', 'accuracy' => array('month' => 'month'))
|
||||||
|
);
|
||||||
|
$this->assertEquals('1 month ago', $result);
|
||||||
|
|
||||||
|
$timestamp = strtotime('-1 years -2 weeks -3 days');
|
||||||
|
$result = $this->Time->timeAgoInWords(
|
||||||
|
$timestamp,
|
||||||
|
array('accuracy' => array('year' => 'year'))
|
||||||
|
);
|
||||||
|
$expected = 'on ' . date('j/n/y', $timestamp);
|
||||||
|
$this->assertEquals($expected, $result);
|
||||||
|
|
||||||
$result = $this->Time->timeAgoInWords(
|
$result = $this->Time->timeAgoInWords(
|
||||||
strtotime('-13 months -5 days'),
|
strtotime('-13 months -5 days'),
|
||||||
array('end' => '2 years')
|
array('end' => '2 years')
|
||||||
);
|
);
|
||||||
$this->assertEquals('1 year, 1 month, 5 days ago', $result);
|
$this->assertEquals('1 year, 1 month, 5 days ago', $result);
|
||||||
|
|
||||||
|
$result = $this->Time->timeAgoInWords(strtotime('-2 hours'));
|
||||||
|
$expected = '2 hours ago';
|
||||||
|
$this->assertEquals($expected, $result);
|
||||||
|
|
||||||
|
$result = $this->Time->timeAgoInWords(strtotime('-12 minutes'));
|
||||||
|
$expected = '12 minutes ago';
|
||||||
|
$this->assertEquals($expected, $result);
|
||||||
|
|
||||||
|
$result = $this->Time->timeAgoInWords(strtotime('-12 seconds'));
|
||||||
|
$expected = '12 seconds ago';
|
||||||
|
$this->assertEquals($expected, $result);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -700,10 +700,10 @@ class CakeTime {
|
||||||
$accuracy = self::$wordAccuracy;
|
$accuracy = self::$wordAccuracy;
|
||||||
|
|
||||||
if (is_array($options)) {
|
if (is_array($options)) {
|
||||||
if (isset($options['userOffset'])) {
|
if (isset($options['timezone'])) {
|
||||||
$timezone = $options['userOffset'];
|
|
||||||
} elseif (isset($options['timezone'])) {
|
|
||||||
$timezone = $options['timezone'];
|
$timezone = $options['timezone'];
|
||||||
|
} elseif (isset($options['userOffset'])) {
|
||||||
|
$timezone = $options['userOffset'];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($options['accuracy'])) {
|
if (isset($options['accuracy'])) {
|
||||||
|
@ -718,12 +718,11 @@ class CakeTime {
|
||||||
|
|
||||||
if (isset($options['format'])) {
|
if (isset($options['format'])) {
|
||||||
$format = $options['format'];
|
$format = $options['format'];
|
||||||
unset($options['format']);
|
|
||||||
}
|
}
|
||||||
if (isset($options['end'])) {
|
if (isset($options['end'])) {
|
||||||
$end = $options['end'];
|
$end = $options['end'];
|
||||||
unset($options['end']);
|
|
||||||
}
|
}
|
||||||
|
unset($options['end'], $options['format']);
|
||||||
} else {
|
} else {
|
||||||
$format = $options;
|
$format = $options;
|
||||||
}
|
}
|
||||||
|
@ -840,11 +839,6 @@ class CakeTime {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// If within the last or next 7 days
|
|
||||||
if (self::wasWithinLast('7 days', $dateTime, $timezone) || self::isWithinNext('7 days', $dateTime, $timezone)) {
|
|
||||||
$relativeDate = self::niceShort($dateTime , $timezone);
|
|
||||||
}
|
|
||||||
|
|
||||||
// If now
|
// If now
|
||||||
if ($diff == 0) {
|
if ($diff == 0) {
|
||||||
$relativeDate = __d('cake', 'just now', 'just now');
|
$relativeDate = __d('cake', 'just now', 'just now');
|
||||||
|
|
Loading…
Reference in a new issue