From a6b93f7ef64a61054cab35615946e6995bfb9c4a Mon Sep 17 00:00:00 2001 From: oleibman <10341515+oleibman@users.noreply.github.com> Date: Mon, 27 Feb 2023 22:52:54 -0800 Subject: [PATCH] TEXT Function Ignores Time in DateTimeStamp Fix #3409. Calculate both the date and time portions when a date/time format is supplied for the TEXT function. --- src/PhpSpreadsheet/Calculation/TextData/Format.php | 2 +- tests/data/Calculation/TextData/TEXT.php | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/PhpSpreadsheet/Calculation/TextData/Format.php b/src/PhpSpreadsheet/Calculation/TextData/Format.php index 93e728202f..5e0762fd69 100644 --- a/src/PhpSpreadsheet/Calculation/TextData/Format.php +++ b/src/PhpSpreadsheet/Calculation/TextData/Format.php @@ -129,7 +129,7 @@ public static function TEXTFORMAT($value, $format) $format = Helpers::extractString($format); if (!is_numeric($value) && Date::isDateTimeFormatCode($format)) { - $value = DateTimeExcel\DateValue::fromString($value); + $value = DateTimeExcel\DateValue::fromString($value) + DateTimeExcel\TimeValue::fromString($value); } return (string) NumberFormat::toFormattedString($value, $format); diff --git a/tests/data/Calculation/TextData/TEXT.php b/tests/data/Calculation/TextData/TEXT.php index 1c7c338adb..5bf87a87df 100644 --- a/tests/data/Calculation/TextData/TEXT.php +++ b/tests/data/Calculation/TextData/TEXT.php @@ -61,6 +61,16 @@ '1-Jan-2012', 'yyyy-mm-dd', ], + 'time (issue 3409)' => [ + '09:01:00', + '09:01', + 'HH:MM:SS', + ], + 'datetime' => [ + '15-Feb-2014 04:17:00 PM', + '2014-02-15 16:17', + 'dd-mmm-yyyy HH:MM:SS AM/PM', + ], [ '1 3/4', 1.75,