Files
oleibman 11854514a0 Changes to NUMBERVALUE, VALUE, DATEVALUE, TIMEVALUE (#3575)
* Changes to NUMBERVALUE, VALUE, DATEVALUE, TIMEVALUE

Fix #3574. Reporter received deprecation notice for NUMBERVALUE function with invalid arguments. In fact, the arguments turn out to be valid after all; NUMBERVALUE treats a null-string or an all-blank-string in the first argument as if it were 0. Fixed this, and added several test cases suggested by it.

VALUE had been parsing its argument the same way as NUMBERVALUE. However, VALUE does not substitute 0 for null-string or all-blank-string. Coded up the difference between the two, and added the same tests for VALUE as for NUMBERVALUE.

VALUE can also pass its argument to DATEVALUE or TIMEVALUE. It is currently over-permissive about that, because Php is over-permissive, e.g. `new DateTime('q')` will return a DateTime object with the current date and time with a timezone of 'q'. Excel will, naturally, return `#VALUE!` for `DATEVALUE('q')`. I don't know that we can ever match Excel's (AFAIK not formally documented) decisions here 100%, but we can get a lot closer by parsing the date string if and only if it contains at least one digit. Code to enforce that is added to DATEVALUE and TIMEVALUE, and appropriate tests are added.

* Failure for Php 7.4 Linux

After not seeing any such problem for many months, this is the second day in a row where result is different on Windows than Linux with no apparent reason to think why that should be the case. At any rate, easily solved.
2023-05-23 08:49:34 -07:00

23 lines
635 B
PHP

<?php
use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError;
return [
[0, '12:00:00 am'],
[0.000717593, '12:01:02 am'],
[0.502083333, '12:03 pm'],
[0.504988426, '12:7:11 pm'],
[0.176145833, '4:13:39'],
[0.764085648, '6:20:17 pm'],
[0.773229167, '18:33:27'],
[0.143923611, '31/12/2007 03:27:15'],
[0.906192133, '9:44:55 pm'],
[ExcelError::VALUE(), 12],
[0.5423611101, '13:01'],
[0.40625, '33:45'],
[ExcelError::VALUE(), '13:01PM'],
[ExcelError::VALUE(), false],
[ExcelError::VALUE(), true],
'do not try to parse if no digits' => [ExcelError::VALUE(), 'x'],
];