Skip to content

Commit

Permalink
PHPExcel dateTime support improved
Browse files Browse the repository at this point in the history
  • Loading branch information
ThaDafinser authored Nov 9, 2016
1 parent ec08a0c commit 64d436a
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions src/ZfcDatagrid/Renderer/PHPExcel/Renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,26 @@ public function execute()
break;

case 'ZfcDatagrid\Column\Type\DateTime':
if ($value instanceof \DateTime) {
$value->setTimezone(new \DateTimeZone($col->getType()
->getOutputTimezone()));
/* @var $dateType \ZfcDatagrid\Column\Type\DateTime */
$dateType = $col->getType();

if (! $value instanceof \DateTime && is_scalar($value)) {
$value = \DateTime::createFromFormat($dateType->getSourceDateTimeFormat(), $value);
$value->setTimezone(new \DateTimeZone($dateType->getSourceTimezone()));
}

$value->setTimezone(new \DateTimeZone($dateType->getOutputTimezone()));
$cell->setValue(\PHPExcel_Shared_Date::PHPToExcel($value));
$cell->getStyle()
->getNumberFormat()
->setFormatCode(\PHPExcel_Style_NumberFormat::FORMAT_DATE_DATETIME);

if ($dateType->getOutputPattern()) {
$outputPattern = $dateType->getOutputPattern();
} else {
$outputPattern = \PHPExcel_Style_NumberFormat::FORMAT_DATE_DATETIME;
}

$cell->$cell->getStyle()
->getNumberFormat()
->setFormatCode($outputPattern);
break;

default:
Expand Down

0 comments on commit 64d436a

Please sign in to comment.