Skip to content

Commit

Permalink
Merge pull request #150 from FriendsOfCake/datetimewidget
Browse files Browse the repository at this point in the history
Datetimewidget
  • Loading branch information
jippi authored Nov 20, 2016
2 parents 90d7824 + 305f92b commit f0bdeaf
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/View/Widget/DateTimeWidget.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Cake\I18n\Time;
use Cake\View\Form\ContextInterface;
use DateTimeInterface;
use DateTimeZone;

class DateTimeWidget extends \Cake\View\Widget\DateTimeWidget
{
Expand All @@ -28,7 +29,7 @@ public function render(array $data, ContextInterface $context)
$disabled = isset($data['disabled']) && $data['disabled'] ? 'disabled' : '';
$role = isset($data['role']) ? $data['role'] : 'datetime-picker';
$format = null;
$locale = I18n::locale();
$locale = isset($data['locale']) ? $data['locale'] : I18n::locale();

$timezoneAware = Configure::read('CrudView.timezoneAwareDateTimeWidget');

Expand All @@ -44,9 +45,11 @@ public function render(array $data, ContextInterface $context)
}

if ($val) {
$timestamp = $val->format('U');
$dateTimeZone = new \DateTimeZone(date_default_timezone_get());
$timezoneOffset = ($dateTimeZone->getOffset($val) / 60);
if ($timezoneAware) {
$timestamp = $val->format('U');
$dateTimeZone = new DateTimeZone(date_default_timezone_get());
$timezoneOffset = ($dateTimeZone->getOffset($val) / 60);
}
$val = $val->format($type === 'date' ? 'Y-m-d' : 'Y-m-d H:i:s');
}

Expand Down

0 comments on commit f0bdeaf

Please sign in to comment.