mirror of
https://github.com/PHPOffice/PhpSpreadsheet.git
synced 2026-09-26 05:28: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.
60 lines
1.7 KiB
PHP
60 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\DateTime;
|
|
|
|
use PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel\Datefunc;
|
|
|
|
class DateTest extends AllSetupTeardown
|
|
{
|
|
/**
|
|
* @dataProvider providerDATE
|
|
*
|
|
* @param mixed $expectedResult
|
|
*/
|
|
public function testDATE($expectedResult, string $formula): void
|
|
{
|
|
$this->mightHaveException($expectedResult);
|
|
$sheet = $this->sheet;
|
|
$sheet->getCell('B1')->setValue('1954-11-23');
|
|
$sheet->getCell('A1')->setValue("=DATE($formula)");
|
|
self::assertEquals($expectedResult, $sheet->getCell('A1')->getCalculatedValue());
|
|
}
|
|
|
|
public function providerDATE(): array
|
|
{
|
|
return require 'tests/data/Calculation/DateTime/DATE.php';
|
|
}
|
|
|
|
public function testDATEtoUnixTimestamp(): void
|
|
{
|
|
self::setUnixReturn();
|
|
|
|
$result = Datefunc::evaluate(2012, 1, 31); // 32-bit safe
|
|
self::assertEquals(1327968000, $result);
|
|
}
|
|
|
|
public function testDATEtoDateTimeObject(): void
|
|
{
|
|
self::setObjectReturn();
|
|
|
|
$result = Datefunc::evaluate(2012, 1, 31);
|
|
// 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'), '31-Jan-2012');
|
|
}
|
|
|
|
public function testDATEwith1904Calendar(): void
|
|
{
|
|
self::setMac1904();
|
|
|
|
$result = Datefunc::evaluate(1918, 11, 11);
|
|
self::assertEquals($result, 5428);
|
|
|
|
$result = Datefunc::evaluate(1901, 1, 31);
|
|
self::assertEquals($result, '#NUM!');
|
|
}
|
|
}
|