mirror of
https://github.com/PHPOffice/PhpSpreadsheet.git
synced 2026-09-25 19:59:52 +00:00
1e8ff9f852
* DateTimeExcel - Change Names of funcWhatever to evaluate Per discussions while MathTrig was being broken up, this would help standardize the code. This PR applies that standardization to the DateTimeExcel family of functions. The deprecation messages in DateTime.php are changed to match the style used in PR #2005. All Phpstan grandfathered errors (about 25) in DateTimeExcel are fixed and removed from baseline. A small number (about 5) of phpstan annotations in the source members in that directory are also fixed and eliminated.
50 lines
1.4 KiB
PHP
50 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\DateTime;
|
|
|
|
use PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel\EDate;
|
|
|
|
class EDateTest extends AllSetupTeardown
|
|
{
|
|
/**
|
|
* @dataProvider providerEDATE
|
|
*
|
|
* @param mixed $expectedResult
|
|
*/
|
|
public function testEDATE($expectedResult, string $formula): void
|
|
{
|
|
$this->mightHaveException($expectedResult);
|
|
$sheet = $this->sheet;
|
|
$sheet->getCell('A1')->setValue("=EDATE($formula)");
|
|
$sheet->getCell('B1')->setValue('1954-11-23');
|
|
self::assertEquals($expectedResult, $sheet->getCell('A1')->getCalculatedValue());
|
|
}
|
|
|
|
public function providerEDATE(): array
|
|
{
|
|
return require 'tests/data/Calculation/DateTime/EDATE.php';
|
|
}
|
|
|
|
public function testEDATEtoUnixTimestamp(): void
|
|
{
|
|
self::setUnixReturn();
|
|
|
|
$result = EDate::evaluate('2012-1-26', -1);
|
|
self::assertEquals(1324857600, $result);
|
|
self::assertEqualsWithDelta(1324857600, $result, 1E-8);
|
|
}
|
|
|
|
public function testEDATEtoDateTimeObject(): void
|
|
{
|
|
self::setObjectReturn();
|
|
|
|
$result = EDate::evaluate('2012-1-26', -1);
|
|
// Must return an object...
|
|
self::assertIsObject($result);
|
|
// ... of the correct type
|
|
self::assertTrue(is_a($result, 'DateTimeInterface'));
|
|
// ... with the correct value
|
|
self::assertEquals($result->format('d-M-Y'), '26-Dec-2011');
|
|
}
|
|
}
|