Skip to content

Commit

Permalink
Use database type class instances to marshal date time strings.
Browse files Browse the repository at this point in the history
  • Loading branch information
ADmad committed Jun 22, 2017
1 parent c892d05 commit 090cc5b
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions src/View/Widget/DateTimeWidget.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
namespace CrudView\View\Widget;

use Cake\Core\Configure;
use Cake\I18n\Date;
use Cake\Database\Type;
use Cake\I18n\I18n;
use Cake\I18n\Time;
use Cake\View\Form\ContextInterface;
use DateTimeInterface;
use DateTimeZone;
Expand Down Expand Up @@ -42,12 +41,14 @@ public function render(array $data, ContextInterface $context)
}

if (!($val instanceof DateTimeInterface) && !empty($val)) {
if ($type === 'date') {
$val = Date::parseDate($val);
} elseif ($type === 'time') {
$val = Time::parseTime($val);
} else {
$val = Time::parseDateTime($val);
switch ($type) {
case 'date':
case 'time':
$val = Type::build($type)->marshal($val);
break;

default:
$val = Type::build('datetime')->marshal($val);
}
}

Expand Down

0 comments on commit 090cc5b

Please sign in to comment.