Handle General number format as non date

If the number format is set to General (id = 0), do no try to format the value as a date
This commit is contained in:
Adrien Loison 2016-05-18 17:29:39 -07:00
parent e9cd7a397e
commit 9c26b241c6
2 changed files with 24 additions and 2 deletions

View File

@ -171,11 +171,23 @@ class StyleHelper
protected function doesNumFmtIdIndicateDate($numFmtId)
{
return (
!$this->doesNumFmtIdIndicateGeneralFormat($numFmtId) &&
(
$this->isNumFmtIdBuiltInDateFormat($numFmtId) ||
$this->isNumFmtIdCustomDateFormat($numFmtId)
)
);
}
/**
* @param int $numFmtId
* @return bool Whether the number format ID indicates the "General" format (0 by convention)
*/
protected function doesNumFmtIdIndicateGeneralFormat($numFmtId)
{
return ($numFmtId === 0);
}
/**
* @param int $numFmtId
* @return bool Whether the number format ID indicates that the number is a timestamp

View File

@ -59,6 +59,16 @@ class StyleHelperTest extends \PHPUnit_Framework_TestCase
$this->assertFalse($shouldFormatAsDate);
}
/**
* @return void
*/
public function testShouldFormatNumericValueAsDateWithGeneralFormat()
{
$styleHelper = $this->getStyleHelperMock([[], ['applyNumberFormat' => true, 'numFmtId' => 0]]);
$shouldFormatAsDate = $styleHelper->shouldFormatNumericValueAsDate(1);
$this->assertFalse($shouldFormatAsDate);
}
/**
* @return void
*/