diff --git a/src/View/Widget/DateTimeWidget.php b/src/View/Widget/DateTimeWidget.php index 20e61e40..1ff8cb9a 100644 --- a/src/View/Widget/DateTimeWidget.php +++ b/src/View/Widget/DateTimeWidget.php @@ -6,6 +6,7 @@ use Cake\I18n\Time; use Cake\View\Form\ContextInterface; use DateTimeInterface; +use DateTimeZone; class DateTimeWidget extends \Cake\View\Widget\DateTimeWidget { @@ -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'); @@ -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'); }