Permit Date/Time Entered on Spreadsheet to be Calculated as Float (#3121)

* Permit Date/Time Entered on Spreadsheet to be Calculated as Float

Fix #1416. I do not entirely understand the use case for this old issue, but resolving it seems straightforward. Issue complains that user-entered date/time fields may be interpreted as either float or int when PhpSpreadsheet reads them. Issue suggests getCalculatedValue treat all date/time fields as float; that seems like a breaking change. However, adding an option to permit it seems okay. That option might be implemented as either a property of Calculation, or a static property of Cell. Since the changed logic is found in Cell (and Shared/Date), I opted for the latter.

In Cell, the property `$parent` is incorrectly described in doc block as `Cells`, and should be `?Cells`. This change eliminates some Phpstan and Scrutinizer problems, and should allow the elimination of some try/catch blocks - I have not done an exhaustive search for those.

Calls to `isDateTime` could have affected activeSheet and selectedCells; they no longer can. Optional parameters are added to it and the functions it calls to accommodate the new functionality; the defaults for the new parameters will, of course, return the same result as the earlier versions of the functions would have returned.

* Scrutinizer - Self-inflicted

Tests used constant which I deprecated.
This commit is contained in:
oleibman
2022-10-18 18:58:38 -07:00
committed by GitHub
parent 6842ccb862
commit e4e99b8a73
12 changed files with 481 additions and 101 deletions
+1 -1
View File
@@ -81,7 +81,7 @@ $spreadsheet->getActiveSheet()
$spreadsheet->getActiveSheet()
->getStyle('C9')
->getNumberFormat()
->setFormatCode(NumberFormat::FORMAT_DATE_YYYYMMDD2);
->setFormatCode(NumberFormat::FORMAT_DATE_YYYYMMDD);
$spreadsheet->getActiveSheet()
->setCellValue('A10', 'Date/Time')