Skip to content

Commit

Permalink
Fix time value display
Browse files Browse the repository at this point in the history
  • Loading branch information
ADmad committed Dec 22, 2020
1 parent 39b8ff7 commit 38e4994
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/View/Helper/CrudViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -231,15 +231,15 @@ public function formatTime(string $field, $value, array $options): string
if ($value === null) {
return $this->Html->badge(__d('crud', 'N/A'), ['class' => 'info']);
}
$format = $options['format'] ?? null;
$format = $options['format'] ?? 'KK:mm:ss a';

/** @psalm-suppress ArgumentTypeCoercion */
if (
is_int($value)
|| is_string($value)
|| $value instanceof DateTimeInterface
) {
return $this->Time->nice($value, $format);
return (string)$this->Time->format($value, $format);
}

return $this->Html->badge(__d('crud', 'N/A'), ['class' => 'info']);
Expand Down
4 changes: 2 additions & 2 deletions tests/TestCase/View/Helper/CrudViewHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class CrudViewHelperTest extends TestCase
/**
* Helper to be tested
*
* @var \Cake\View\Helper\CrudViewHelper
* @var \Crud\View\Helper\CrudViewHelper
*/
public $CrudView;

Expand Down Expand Up @@ -70,7 +70,7 @@ public function testIntrospect()
'datetime' => 'formatTime',
]);
$result = $this->CrudView->introspect('created', $value);
$this->assertEquals($this->CrudView->Time->nice($value), $result);
$this->assertEquals($this->CrudView->Time->format($value, 'KK:mm:ss a'), $result);

$this->CrudView->setConfig('fieldFormatters', [
'datetime' => function () {
Expand Down

0 comments on commit 38e4994

Please sign in to comment.