From 088a76737ee295a121172624c0f0b2984a8f0de9 Mon Sep 17 00:00:00 2001 From: Maxim Date: Wed, 4 Oct 2017 06:57:01 +0300 Subject: [PATCH] Fix DAY() function with 0= 0) { + $days = '+' . $days; + } + $interval = $days . ' days'; return $baseDate->modify($interval) ->setTime($hours, $minutes, $seconds); diff --git a/tests/PhpSpreadsheetTests/Calculation/DateTimeTest.php b/tests/PhpSpreadsheetTests/Calculation/DateTimeTest.php index 8959cb00..78ed021f 100644 --- a/tests/PhpSpreadsheetTests/Calculation/DateTimeTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/DateTimeTest.php @@ -174,12 +174,17 @@ class DateTimeTest extends PHPUnit_Framework_TestCase /** * @dataProvider providerDAY * - * @param mixed $expectedResult + * @param mixed $expectedResultExcel + * @param mixed $expectedResultOpenOffice */ - public function testDAY($expectedResult, ...$args) + public function testDAY($expectedResultExcel, $expectedResultOpenOffice, ...$args) { - $result = DateTime::DAYOFMONTH(...$args); - self::assertEquals($expectedResult, $result, null, 1E-8); + $resultExcel = DateTime::DAYOFMONTH(...$args); + self::assertEquals($expectedResultExcel, $resultExcel, null, 1E-8); + + Functions::setCompatibilityMode(Functions::COMPATIBILITY_OPENOFFICE); + $resultOpenOffice = DateTime::DAYOFMONTH(...$args); + self::assertEquals($expectedResultOpenOffice, $resultOpenOffice, null, 1E-8); } public function providerDAY() diff --git a/tests/data/Calculation/DateTime/DAY.php b/tests/data/Calculation/DateTime/DAY.php index 4bcd8e7a..affc4df3 100644 --- a/tests/data/Calculation/DateTime/DAY.php +++ b/tests/data/Calculation/DateTime/DAY.php @@ -4,31 +4,53 @@ return [ [ - 19, + 19, // Result for Excel + 19, // Result for OpenOffice 22269, ], [ - 1, + 1, // Result for Excel + 1, // Result for OpenOffice 30348, ], [ - 10, + 10, // Result for Excel + 10, // Result for OpenOffice 30843, ], [ - 11, + 11, // Result for Excel + 11, // Result for OpenOffice '11-Nov-1918', ], [ - 28, + 28, // Result for Excel + 28, // Result for OpenOffice '28-Feb-1904', ], [ - '#VALUE!', + '#VALUE!', // Result for Excel + '#VALUE!', // Result for OpenOffice 'Invalid', ], [ - '#NUM!', + '#NUM!', // Result for Excel + 29, // Result for OpenOffice -1, ], + [ + 1, // Result for Excel + 31, // Result for OpenOffice + 1, + ], + [ + 0, // Result for Excel + 30, // Result for OpenOffice + 0.5, + ], + [ + 0, // Result for Excel + 30, // Result for OpenOffice + 0, + ], ];