XLSX cells containing date values should respect shouldFormatDate option (#282)
Return the ISO 8601 date string directly if option is set
This commit is contained in:
parent
82605ab57b
commit
b75a3e34fc
@ -283,16 +283,16 @@ class CellValueFormatter
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a cell's PHP Date value, associated to the given stored nodeValue.
|
* Returns a cell's PHP Date value, associated to the given stored nodeValue.
|
||||||
|
* @see ECMA-376 Part 1 - §18.17.4
|
||||||
*
|
*
|
||||||
* @param string $nodeValue
|
* @param string $nodeValue ISO 8601 Date string
|
||||||
* @return \DateTime|null The value associated with the cell or NULL if invalid date value
|
* @return \DateTime|string|null The value associated with the cell or NULL if invalid date value
|
||||||
*/
|
*/
|
||||||
protected function formatDateCellValue($nodeValue)
|
protected function formatDateCellValue($nodeValue)
|
||||||
{
|
{
|
||||||
// Mitigate thrown Exception on invalid date-time format (http://php.net/manual/en/datetime.construct.php)
|
// Mitigate thrown Exception on invalid date-time format (http://php.net/manual/en/datetime.construct.php)
|
||||||
try {
|
try {
|
||||||
$cellValue = new \DateTime($nodeValue);
|
return ($this->shouldFormatDates) ? $nodeValue : new \DateTime($nodeValue);
|
||||||
return $cellValue;
|
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -274,6 +274,7 @@ class ReaderTest extends \PHPUnit_Framework_TestCase
|
|||||||
$expectedRows = [
|
$expectedRows = [
|
||||||
['1/13/2016', '01/13/2016', '13-Jan-16', 'Wednesday January 13, 16', 'Today is 1/13/2016'],
|
['1/13/2016', '01/13/2016', '13-Jan-16', 'Wednesday January 13, 16', 'Today is 1/13/2016'],
|
||||||
['4:43:25', '04:43', '4:43', '4:43:25 AM', '4:43:25 PM'],
|
['4:43:25', '04:43', '4:43', '4:43:25 AM', '4:43:25 PM'],
|
||||||
|
['1976-11-22T08:30:00.000', '1976-11-22T08:30', '1582-10-15', '08:30:00', '08:30'],
|
||||||
];
|
];
|
||||||
$this->assertEquals($expectedRows, $allRows);
|
$this->assertEquals($expectedRows, $allRows);
|
||||||
}
|
}
|
||||||
|
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user