Skip to content

Commit

Permalink
TEXT Function Ignores Time in DateTimeStamp (#3411)
Browse files Browse the repository at this point in the history
Fix #3409. Calculate both the date and time portions when a date/time format is supplied for the TEXT function.
  • Loading branch information
oleibman authored Mar 2, 2023
1 parent bef3a00 commit 66221bf
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/PhpSpreadsheet/Calculation/TextData/Format.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
10 changes: 10 additions & 0 deletions tests/data/Calculation/TextData/TEXT.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 66221bf

Please sign in to comment.