From 9006d2a3f438ed45e10b1934aab3860fe784f2b4 Mon Sep 17 00:00:00 2001 From: MarkBaker Date: Mon, 6 Mar 2023 17:08:02 +0100 Subject: [PATCH] Fix for Issue #3436 - Result from Excel's EDATE() and EOMONTH() should always be rounded to 0 decimal --- CHANGELOG.md | 1 + src/PhpSpreadsheet/Calculation/DateTimeExcel/Month.php | 2 ++ tests/data/Calculation/DateTime/EDATE.php | 3 +++ tests/data/Calculation/DateTime/EOMONTH.php | 2 ++ 4 files changed, 8 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 71b286beab..095c1259a6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,6 +26,7 @@ and this project adheres to [Semantic Versioning](https://semver.org). ### Fixed - Updates Cell formula absolute ranges/references, and Defined Name absolute ranges/references when inserting/deleting rows/columns [Issue #3368](https://github.com/PHPOffice/PhpSpreadsheet/issues/3368) [PR #3402](https://github.com/PHPOffice/PhpSpreadsheet/pull/3402) +- EOMONTH() and EDATE() Functions should round date value before evaluation [Issue #3436](https://github.com/PHPOffice/PhpSpreadsheet/issues/3436) [PR #3437](https://github.com/PHPOffice/PhpSpreadsheet/pull/3437) ## 1.28.0 - 2023-02-25 diff --git a/src/PhpSpreadsheet/Calculation/DateTimeExcel/Month.php b/src/PhpSpreadsheet/Calculation/DateTimeExcel/Month.php index c72d006b92..5c42eac085 100644 --- a/src/PhpSpreadsheet/Calculation/DateTimeExcel/Month.php +++ b/src/PhpSpreadsheet/Calculation/DateTimeExcel/Month.php @@ -45,6 +45,7 @@ public static function adjust($dateValue, $adjustmentMonths) } catch (Exception $e) { return $e->getMessage(); } + $dateValue = floor($dateValue); $adjustmentMonths = floor($adjustmentMonths); // Execute function @@ -88,6 +89,7 @@ public static function lastDay($dateValue, $adjustmentMonths) } catch (Exception $e) { return $e->getMessage(); } + $dateValue = floor($dateValue); $adjustmentMonths = floor($adjustmentMonths); // Execute function diff --git a/tests/data/Calculation/DateTime/EDATE.php b/tests/data/Calculation/DateTime/EDATE.php index 8427a8c95b..e1d146fc52 100644 --- a/tests/data/Calculation/DateTime/EDATE.php +++ b/tests/data/Calculation/DateTime/EDATE.php @@ -10,9 +10,12 @@ [39416, '"31-Mar-2008", -4'], [39141, '"29-Feb-2008", -12'], [39248, '"15-Mar-2007", 3'], + [39248, '"15-Mar-2007 16:30:00", 3'], [22269, '22269.0, 0'], [22269, '22269.0, Q15'], [22331, '22269.0, 2'], + [22331, '22269.75, 2'], + [22331, '22269.0, 2.5'], [25618, '22269.0, "110"'], [18920, '22269.0, -110'], ['#VALUE!', '"15-Mar-2007", "ABC"'], diff --git a/tests/data/Calculation/DateTime/EOMONTH.php b/tests/data/Calculation/DateTime/EOMONTH.php index b6e020b75b..c0dd4100a6 100644 --- a/tests/data/Calculation/DateTime/EOMONTH.php +++ b/tests/data/Calculation/DateTime/EOMONTH.php @@ -12,6 +12,7 @@ [39416, '"31-Mar-2008", -4'], [39141, '"29-Feb-2008", -12'], [39263, '"15-Mar-2007", 3'], + [39263, '"15-Mar-2007 16:30:00", 3'], [22281, '22269.0, 0'], [22281, '22269.0, Q15'], [22340, '"22269.0", 2'], @@ -19,6 +20,7 @@ [18932, '22269.0, -110'], [22371, '22269.0, 3'], [22371, '22269.0, 3.75'], + [22371, '22269.75, 3'], ['#VALUE!', '"15-Mar-2007", false'], ['#VALUE!', '"15-Mar-2007", true'], ['#VALUE!', '"15-Mar-2007", "ABC"'],