Skip to content

Commit

Permalink
Fix for Issue #3436 - Result from Excel's EDATE() and EOMONTH() shoul…
Browse files Browse the repository at this point in the history
…d always be rounded to 0 decimal
  • Loading branch information
MarkBaker committed Mar 6, 2023
1 parent bb54c89 commit 9006d2a
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/PhpSpreadsheet/Calculation/DateTimeExcel/Month.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public static function adjust($dateValue, $adjustmentMonths)
} catch (Exception $e) {
return $e->getMessage();
}
$dateValue = floor($dateValue);
$adjustmentMonths = floor($adjustmentMonths);

// Execute function
Expand Down Expand Up @@ -88,6 +89,7 @@ public static function lastDay($dateValue, $adjustmentMonths)
} catch (Exception $e) {
return $e->getMessage();
}
$dateValue = floor($dateValue);
$adjustmentMonths = floor($adjustmentMonths);

// Execute function
Expand Down
3 changes: 3 additions & 0 deletions tests/data/Calculation/DateTime/EDATE.php
Original file line number Diff line number Diff line change
Expand Up @@ -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"'],
Expand Down
2 changes: 2 additions & 0 deletions tests/data/Calculation/DateTime/EOMONTH.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@
[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'],
[25627, '22269.0, 110'],
[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"'],
Expand Down

0 comments on commit 9006d2a

Please sign in to comment.