Fix TEXT and TIMEVALUE Functions 2.3 Branch (#4354)

Fix #4249. Technically speaking, only the 1.29 branch needs fixing, and only for TEXT. It was fixed for the other branches by PR #3898. However, in adding test cases for the fix, it became apparent that PhpSpreadsheet's parsing in TIMEVALUE (which is called from TEXT in the original issue) did not really match Excel's. There are probably still edge cases where it doesn't, but, in the absence of a spec for how it operates, this will do for now.

We do not usually backport fixes from the master branch. Because this is more of a forward port from the earlier branch, there is an equivalent PR for each active branch.
This commit is contained in:
oleibman
2025-02-10 20:47:25 -08:00
committed by GitHub
parent e6cc4129b7
commit 4eefcceee8
4 changed files with 84 additions and 10 deletions
+50
View File
@@ -73,6 +73,56 @@ return [
'2014-02-15 16:17',
'dd-mmm-yyyy HH:MM:SS AM/PM',
],
'datetime integer' => [
'1900-01-06 00:00',
6,
'yyyy-mm-dd hh:mm',
],
'datetime integer as string' => [
'1900-01-06 00:00',
'6',
'yyyy-mm-dd hh:mm',
],
'datetime 2 integers without date delimiters' => [
'5 6',
'5 6',
'yyyy-mm-dd hh:mm',
],
'datetime 2 integers separated by hyphen' => [
(new DateTimeImmutable())->format('Y') . '-05-13 00:00',
'5-13',
'yyyy-mm-dd hh:mm',
],
'datetime string date only' => [
'1951-01-23 00:00',
'January 23, 1951',
'yyyy-mm-dd hh:mm',
],
'datetime string time followed by date' => [
'1952-05-02 03:54',
'3:54 May 2, 1952',
'yyyy-mm-dd hh:mm',
],
'datetime string date followed by time pm' => [
'1952-05-02 15:54',
'May 2, 1952 3:54 pm',
'yyyy-mm-dd hh:mm',
],
'datetime string date followed by time p' => [
'1952-05-02 15:54',
'May 2, 1952 3:54 p',
'yyyy-mm-dd hh:mm',
],
'datetime decimal string interpreted as time' => [
'1900-01-02 12:00',
'2.5',
'yyyy-mm-dd hh:mm',
],
'datetime unparseable string' => [
'xyz',
'xyz',
'yyyy-mm-dd hh:mm',
],
[
'1 3/4',
1.75,