Skip to content

Commit

Permalink
Fix published() to work with FrozenTime
Browse files Browse the repository at this point in the history
  • Loading branch information
dereuromark committed Dec 27, 2019
1 parent a368364 commit 0d54da1
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
9 changes: 3 additions & 6 deletions src/View/Helper/TimeHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,20 +143,17 @@ public function niceDateMarkup($dateString = null, $format = null, $options = []
* Returns red/specialGreen/green date depending on the current day
* // TODO refactor! $userOffset is deprecated!
*
* @param \DateTime $date Date
* @param \DateTimeInterface $date Date
* @param array $options
* @param array $attr HTML attributes
* @return string Nicely formatted date
*/
public function published(DateTime $date, array $options = [], array $attr = []) {
$niceDate = '';
public function published($date, array $options = [], array $attr = []) {
$when = null;
$span = '';
$spanEnd = '';
$whenArray = ['-1' => 'already', '0' => 'today', '1' => 'notyet'];
$titles = ['-1' => __d('tools', 'publishedAlready'), '0' => __d('tools', 'publishedToday'), '1' => __d('tools', 'publishedNotYet')];

$y = $this->isThisYear($date) ? '' : ' Y';
//$y = $this->isThisYear($date) ? '' : ' Y';

$format = (!empty($options['format']) ? $options['format'] : FORMAT_NICE_YMD);

Expand Down
3 changes: 2 additions & 1 deletion tests/TestCase/View/Helper/TimeHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Tools\Test\TestCase\View\Helper;

use Cake\I18n\FrozenTime;
use Cake\View\View;
use Tools\TestSuite\TestCase;
use Tools\Utility\Time;
Expand Down Expand Up @@ -78,7 +79,7 @@ public function testPublished() {
$expected = 'class="published notyet';
$this->assertContains($expected, $result);

$result = $this->Time->published((new Time(date(FORMAT_DB_DATETIME)))->subDays(2));
$result = $this->Time->published((new FrozenTime(date(FORMAT_DB_DATETIME)))->subDays(2));
$expected = 'class="published already';
$this->assertContains($expected, $result);
}
Expand Down

0 comments on commit 0d54da1

Please sign in to comment.