Refactoring of date time tests (#1101)

* Merge branch 'master' of C:\Projects\PHPOffice\PHPSpreadsheet\develop with conflicts.

* Separate out date/time tests into individual tests

* Need to update the version of phpunit at some point to deal with the new assertions and deprecated assertions

* Appease the CS Gods

* More refactoring of Date/Time tests

* Replace self assertions with instance assertions (looking forward to upgrading phpunit)

* Finish refactoring of date/time tests as individual tests

* Test for DateTimeInterface rather than for DateTime

* A few strict comparisons

* Fix to test names
This commit is contained in:
Mark Baker 2019-07-21 20:55:41 +02:00 committed by GitHub
parent ba2b74c222
commit 9ad6de620e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
53 changed files with 1064 additions and 920 deletions

View File

@ -16,7 +16,7 @@ class DateTime
*/
public static function isLeapYear($year)
{
return (($year % 4) == 0) && (($year % 100) != 0) || (($year % 400) == 0);
return (($year % 4) === 0) && (($year % 100) !== 0) || (($year % 400) === 0);
}
/**
@ -156,11 +156,11 @@ class DateTime
$retValue = (float) Date::PHPToExcel(time());
break;
case Functions::RETURNDATE_PHP_NUMERIC:
case Functions::RETURNDATE_UNIX_TIMESTAMP:
$retValue = (int) time();
break;
case Functions::RETURNDATE_PHP_OBJECT:
case Functions::RETURNDATE_PHP_DATETIME_OBJECT:
$retValue = new \DateTime();
break;
@ -200,11 +200,11 @@ class DateTime
$retValue = (float) $excelDateTime;
break;
case Functions::RETURNDATE_PHP_NUMERIC:
case Functions::RETURNDATE_UNIX_TIMESTAMP:
$retValue = (int) Date::excelToTimestamp($excelDateTime);
break;
case Functions::RETURNDATE_PHP_OBJECT:
case Functions::RETURNDATE_PHP_DATETIME_OBJECT:
$retValue = Date::excelToDateTimeObject($excelDateTime);
break;
@ -325,9 +325,9 @@ class DateTime
switch (Functions::getReturnDateType()) {
case Functions::RETURNDATE_EXCEL:
return (float) $excelDateValue;
case Functions::RETURNDATE_PHP_NUMERIC:
case Functions::RETURNDATE_UNIX_TIMESTAMP:
return (int) Date::excelToTimestamp($excelDateValue);
case Functions::RETURNDATE_PHP_OBJECT:
case Functions::RETURNDATE_PHP_DATETIME_OBJECT:
return Date::excelToDateTimeObject($excelDateValue);
}
}
@ -420,9 +420,9 @@ class DateTime
}
return (float) Date::formattedPHPToExcel($calendar, 1, $date, $hour, $minute, $second);
case Functions::RETURNDATE_PHP_NUMERIC:
case Functions::RETURNDATE_UNIX_TIMESTAMP:
return (int) Date::excelToTimestamp(Date::formattedPHPToExcel(1970, 1, 1, $hour, $minute, $second)); // -2147468400; // -2147472000 + 3600
case Functions::RETURNDATE_PHP_OBJECT:
case Functions::RETURNDATE_PHP_DATETIME_OBJECT:
$dayAdjust = 0;
if ($hour < 0) {
$dayAdjust = floor($hour / 24);
@ -472,7 +472,6 @@ class DateTime
*/
public static function DATEVALUE($dateValue = 1)
{
$dateValueOrig = $dateValue;
$dateValue = trim(Functions::flattenSingleValue($dateValue), '"');
// Strip any ordinals because they're allowed in Excel (English only)
$dateValue = preg_replace('/(\d)(st|nd|rd|th)([ -\/])/Ui', '$1$3', $dateValue);
@ -569,9 +568,9 @@ class DateTime
switch (Functions::getReturnDateType()) {
case Functions::RETURNDATE_EXCEL:
return (float) $excelDateValue;
case Functions::RETURNDATE_PHP_NUMERIC:
case Functions::RETURNDATE_UNIX_TIMESTAMP:
return (int) Date::excelToTimestamp($excelDateValue);
case Functions::RETURNDATE_PHP_OBJECT:
case Functions::RETURNDATE_PHP_DATETIME_OBJECT:
return new \DateTime($PHPDateArray['year'] . '-' . $PHPDateArray['month'] . '-' . $PHPDateArray['day'] . ' 00:00:00');
}
}
@ -631,9 +630,9 @@ class DateTime
switch (Functions::getReturnDateType()) {
case Functions::RETURNDATE_EXCEL:
return (float) $excelDateValue;
case Functions::RETURNDATE_PHP_NUMERIC:
case Functions::RETURNDATE_UNIX_TIMESTAMP:
return (int) $phpDateValue = Date::excelToTimestamp($excelDateValue + 25569) - 3600;
case Functions::RETURNDATE_PHP_OBJECT:
case Functions::RETURNDATE_PHP_DATETIME_OBJECT:
return new \DateTime('1900-01-01 ' . $PHPDateArray['hour'] . ':' . $PHPDateArray['minute'] . ':' . $PHPDateArray['second']);
}
}
@ -683,7 +682,6 @@ class DateTime
$endMonths = $PHPEndDateObject->format('n');
$endYears = $PHPEndDateObject->format('Y');
$retVal = Functions::NAN();
switch ($unit) {
case 'D':
$retVal = (int) $difference;
@ -1154,9 +1152,9 @@ class DateTime
switch (Functions::getReturnDateType()) {
case Functions::RETURNDATE_EXCEL:
return (float) $endDate;
case Functions::RETURNDATE_PHP_NUMERIC:
case Functions::RETURNDATE_UNIX_TIMESTAMP:
return (int) Date::excelToTimestamp($endDate);
case Functions::RETURNDATE_PHP_OBJECT:
case Functions::RETURNDATE_PHP_DATETIME_OBJECT:
return Date::excelToDateTimeObject($endDate);
}
}
@ -1239,7 +1237,7 @@ class DateTime
// Execute function
$PHPDateObject = Date::excelToDateTimeObject($dateValue);
$DoW = $PHPDateObject->format('w');
$DoW = (int) $PHPDateObject->format('w');
$firstDay = 1;
switch ($style) {
@ -1248,13 +1246,13 @@ class DateTime
break;
case 2:
if ($DoW == 0) {
if ($DoW === 0) {
$DoW = 7;
}
break;
case 3:
if ($DoW == 0) {
if ($DoW === 0) {
$DoW = 7;
}
$firstDay = 0;
@ -1272,7 +1270,7 @@ class DateTime
}
}
return (int) $DoW;
return $DoW;
}
/**
@ -1591,9 +1589,9 @@ class DateTime
switch (Functions::getReturnDateType()) {
case Functions::RETURNDATE_EXCEL:
return (float) Date::PHPToExcel($PHPDateObject);
case Functions::RETURNDATE_PHP_NUMERIC:
case Functions::RETURNDATE_UNIX_TIMESTAMP:
return (int) Date::excelToTimestamp(Date::PHPToExcel($PHPDateObject));
case Functions::RETURNDATE_PHP_OBJECT:
case Functions::RETURNDATE_PHP_DATETIME_OBJECT:
return $PHPDateObject;
}
}
@ -1640,9 +1638,9 @@ class DateTime
switch (Functions::getReturnDateType()) {
case Functions::RETURNDATE_EXCEL:
return (float) Date::PHPToExcel($PHPDateObject);
case Functions::RETURNDATE_PHP_NUMERIC:
case Functions::RETURNDATE_UNIX_TIMESTAMP:
return (int) Date::excelToTimestamp(Date::PHPToExcel($PHPDateObject));
case Functions::RETURNDATE_PHP_OBJECT:
case Functions::RETURNDATE_PHP_DATETIME_OBJECT:
return $PHPDateObject;
}
}

View File

@ -17,8 +17,11 @@ class Functions
const COMPATIBILITY_EXCEL = 'Excel';
const COMPATIBILITY_GNUMERIC = 'Gnumeric';
const COMPATIBILITY_OPENOFFICE = 'OpenOfficeCalc';
const RETURNDATE_PHP_NUMERIC = 'P';
const RETURNDATE_UNIX_TIMESTAMP = 'P';
const RETURNDATE_PHP_OBJECT = 'O';
const RETURNDATE_PHP_DATETIME_OBJECT = 'O';
const RETURNDATE_EXCEL = 'E';
/**
@ -101,16 +104,16 @@ class Functions
*
* @param string $returnDateType Return Date Format
* Permitted values are:
* Functions::RETURNDATE_PHP_NUMERIC 'P'
* Functions::RETURNDATE_PHP_OBJECT 'O'
* Functions::RETURNDATE_UNIX_TIMESTAMP 'P'
* Functions::RETURNDATE_PHP_DATETIME_OBJECT 'O'
* Functions::RETURNDATE_EXCEL 'E'
*
* @return bool Success or failure
*/
public static function setReturnDateType($returnDateType)
{
if (($returnDateType == self::RETURNDATE_PHP_NUMERIC) ||
($returnDateType == self::RETURNDATE_PHP_OBJECT) ||
if (($returnDateType == self::RETURNDATE_UNIX_TIMESTAMP) ||
($returnDateType == self::RETURNDATE_PHP_DATETIME_OBJECT) ||
($returnDateType == self::RETURNDATE_EXCEL)
) {
self::$returnDateType = $returnDateType;
@ -128,8 +131,8 @@ class Functions
*
* @return string Return Date Format
* Possible Return values are:
* Functions::RETURNDATE_PHP_NUMERIC 'P'
* Functions::RETURNDATE_PHP_OBJECT 'O'
* Functions::RETURNDATE_UNIX_TIMESTAMP 'P'
* Functions::RETURNDATE_PHP_DATETIME_OBJECT 'O'
* Functions::RETURNDATE_EXCEL 'E'
*/
public static function getReturnDateType()

View File

@ -1,503 +0,0 @@
<?php
namespace PhpOffice\PhpSpreadsheetTests\Calculation;
use PhpOffice\PhpSpreadsheet\Calculation\DateTime;
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
use PhpOffice\PhpSpreadsheet\Shared\Date;
use PHPUnit\Framework\TestCase;
/**
* Class DateTimeTest.
*/
class DateTimeTest extends TestCase
{
public function setUp()
{
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
}
/**
* @dataProvider providerDATE
*
* @param mixed $expectedResult
*/
public function testDATE($expectedResult, ...$args)
{
$result = DateTime::DATE(...$args);
self::assertEquals($expectedResult, $result, null, 1E-8);
}
public function providerDATE()
{
return require 'data/Calculation/DateTime/DATE.php';
}
public function testDATEtoPHP()
{
Functions::setReturnDateType(Functions::RETURNDATE_PHP_NUMERIC);
$result = DateTime::DATE(2012, 1, 31);
Functions::setReturnDateType(Functions::RETURNDATE_EXCEL);
self::assertEquals(1327968000, $result, null, 1E-8);
}
public function testDATEtoPHPObject()
{
Functions::setReturnDateType(Functions::RETURNDATE_PHP_OBJECT);
$result = DateTime::DATE(2012, 1, 31);
Functions::setReturnDateType(Functions::RETURNDATE_EXCEL);
// Must return an object...
self::assertInternalType('object', $result);
// ... of the correct type
self::assertTrue(is_a($result, 'DateTime'));
// ... with the correct value
self::assertEquals($result->format('d-M-Y'), '31-Jan-2012');
}
public function testDATEwith1904Calendar()
{
Date::setExcelCalendar(Date::CALENDAR_MAC_1904);
$result = DateTime::DATE(1918, 11, 11);
Date::setExcelCalendar(Date::CALENDAR_WINDOWS_1900);
self::assertEquals($result, 5428);
}
public function testDATEwith1904CalendarError()
{
Date::setExcelCalendar(Date::CALENDAR_MAC_1904);
$result = DateTime::DATE(1901, 1, 31);
Date::setExcelCalendar(Date::CALENDAR_WINDOWS_1900);
self::assertEquals($result, '#NUM!');
}
/**
* @dataProvider providerDATEVALUE
*
* @param mixed $expectedResult
*/
public function testDATEVALUE($expectedResult, ...$args)
{
$result = DateTime::DATEVALUE(...$args);
self::assertEquals($expectedResult, $result, null, 1E-8);
}
public function providerDATEVALUE()
{
return require 'data/Calculation/DateTime/DATEVALUE.php';
}
public function testDATEVALUEtoPHP()
{
Functions::setReturnDateType(Functions::RETURNDATE_PHP_NUMERIC);
$result = DateTime::DATEVALUE('2012-1-31');
Functions::setReturnDateType(Functions::RETURNDATE_EXCEL);
self::assertEquals(1327968000, $result, null, 1E-8);
}
public function testDATEVALUEtoPHPObject()
{
Functions::setReturnDateType(Functions::RETURNDATE_PHP_OBJECT);
$result = DateTime::DATEVALUE('2012-1-31');
Functions::setReturnDateType(Functions::RETURNDATE_EXCEL);
// Must return an object...
self::assertInternalType('object', $result);
// ... of the correct type
self::assertTrue(is_a($result, 'DateTime'));
// ... with the correct value
self::assertEquals($result->format('d-M-Y'), '31-Jan-2012');
}
/**
* @dataProvider providerYEAR
*
* @param mixed $expectedResult
*/
public function testYEAR($expectedResult, ...$args)
{
$result = DateTime::YEAR(...$args);
self::assertEquals($expectedResult, $result, null, 1E-8);
}
public function providerYEAR()
{
return require 'data/Calculation/DateTime/YEAR.php';
}
/**
* @dataProvider providerMONTH
*
* @param mixed $expectedResult
*/
public function testMONTH($expectedResult, ...$args)
{
$result = DateTime::MONTHOFYEAR(...$args);
self::assertEquals($expectedResult, $result, null, 1E-8);
}
public function providerMONTH()
{
return require 'data/Calculation/DateTime/MONTH.php';
}
/**
* @dataProvider providerWEEKNUM
*
* @param mixed $expectedResult
*/
public function testWEEKNUM($expectedResult, ...$args)
{
$result = DateTime::WEEKNUM(...$args);
self::assertEquals($expectedResult, $result, null, 1E-8);
}
public function providerWEEKNUM()
{
return require 'data/Calculation/DateTime/WEEKNUM.php';
}
/**
* @dataProvider providerISOWEEKNUM
*
* @param mixed $expectedResult
* @param mixed $dateValue
*/
public function testISOWEEKNUM($expectedResult, $dateValue)
{
$result = DateTime::ISOWEEKNUM($dateValue);
self::assertEquals($expectedResult, $result, null, 1E-8);
}
public function providerISOWEEKNUM()
{
return require 'data/Calculation/DateTime/ISOWEEKNUM.php';
}
/**
* @dataProvider providerWEEKDAY
*
* @param mixed $expectedResult
*/
public function testWEEKDAY($expectedResult, ...$args)
{
$result = DateTime::WEEKDAY(...$args);
self::assertEquals($expectedResult, $result, null, 1E-8);
}
public function providerWEEKDAY()
{
return require 'data/Calculation/DateTime/WEEKDAY.php';
}
/**
* @dataProvider providerDAY
*
* @param mixed $expectedResultExcel
* @param mixed $expectedResultOpenOffice
*/
public function testDAY($expectedResultExcel, $expectedResultOpenOffice, ...$args)
{
$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()
{
return require 'data/Calculation/DateTime/DAY.php';
}
/**
* @dataProvider providerTIME
*
* @param mixed $expectedResult
*/
public function testTIME($expectedResult, ...$args)
{
$result = DateTime::TIME(...$args);
self::assertEquals($expectedResult, $result, null, 1E-8);
}
public function providerTIME()
{
return require 'data/Calculation/DateTime/TIME.php';
}
public function testTIMEtoPHP()
{
Functions::setReturnDateType(Functions::RETURNDATE_PHP_NUMERIC);
$result = DateTime::TIME(7, 30, 20);
Functions::setReturnDateType(Functions::RETURNDATE_EXCEL);
self::assertEquals(27020, $result, null, 1E-8);
}
public function testTIMEtoPHPObject()
{
Functions::setReturnDateType(Functions::RETURNDATE_PHP_OBJECT);
$result = DateTime::TIME(7, 30, 20);
Functions::setReturnDateType(Functions::RETURNDATE_EXCEL);
// Must return an object...
self::assertInternalType('object', $result);
// ... of the correct type
self::assertTrue(is_a($result, 'DateTime'));
// ... with the correct value
self::assertEquals($result->format('H:i:s'), '07:30:20');
}
/**
* @dataProvider providerTIMEVALUE
*
* @param mixed $expectedResult
*/
public function testTIMEVALUE($expectedResult, ...$args)
{
$result = DateTime::TIMEVALUE(...$args);
self::assertEquals($expectedResult, $result, null, 1E-8);
}
public function providerTIMEVALUE()
{
return require 'data/Calculation/DateTime/TIMEVALUE.php';
}
public function testTIMEVALUEtoPHP()
{
Functions::setReturnDateType(Functions::RETURNDATE_PHP_NUMERIC);
$result = DateTime::TIMEVALUE('7:30:20');
Functions::setReturnDateType(Functions::RETURNDATE_EXCEL);
self::assertEquals(23420, $result, null, 1E-8);
}
public function testTIMEVALUEtoPHPObject()
{
Functions::setReturnDateType(Functions::RETURNDATE_PHP_OBJECT);
$result = DateTime::TIMEVALUE('7:30:20');
Functions::setReturnDateType(Functions::RETURNDATE_EXCEL);
// Must return an object...
self::assertInternalType('object', $result);
// ... of the correct type
self::assertTrue(is_a($result, 'DateTime'));
// ... with the correct value
self::assertEquals($result->format('H:i:s'), '07:30:20');
}
/**
* @dataProvider providerHOUR
*
* @param mixed $expectedResult
*/
public function testHOUR($expectedResult, ...$args)
{
$result = DateTime::HOUROFDAY(...$args);
self::assertEquals($expectedResult, $result, null, 1E-8);
}
public function providerHOUR()
{
return require 'data/Calculation/DateTime/HOUR.php';
}
/**
* @dataProvider providerMINUTE
*
* @param mixed $expectedResult
*/
public function testMINUTE($expectedResult, ...$args)
{
$result = DateTime::MINUTE(...$args);
self::assertEquals($expectedResult, $result, null, 1E-8);
}
public function providerMINUTE()
{
return require 'data/Calculation/DateTime/MINUTE.php';
}
/**
* @dataProvider providerSECOND
*
* @param mixed $expectedResult
*/
public function testSECOND($expectedResult, ...$args)
{
$result = DateTime::SECOND(...$args);
self::assertEquals($expectedResult, $result, null, 1E-8);
}
public function providerSECOND()
{
return require 'data/Calculation/DateTime/SECOND.php';
}
/**
* @dataProvider providerNETWORKDAYS
*
* @param mixed $expectedResult
*/
public function testNETWORKDAYS($expectedResult, ...$args)
{
$result = DateTime::NETWORKDAYS(...$args);
self::assertEquals($expectedResult, $result, null, 1E-8);
}
public function providerNETWORKDAYS()
{
return require 'data/Calculation/DateTime/NETWORKDAYS.php';
}
/**
* @dataProvider providerWORKDAY
*
* @param mixed $expectedResult
*/
public function testWORKDAY($expectedResult, ...$args)
{
$result = DateTime::WORKDAY(...$args);
self::assertEquals($expectedResult, $result, null, 1E-8);
}
public function providerWORKDAY()
{
return require 'data/Calculation/DateTime/WORKDAY.php';
}
/**
* @dataProvider providerEDATE
*
* @param mixed $expectedResult
*/
public function testEDATE($expectedResult, ...$args)
{
$result = DateTime::EDATE(...$args);
self::assertEquals($expectedResult, $result, null, 1E-8);
}
public function providerEDATE()
{
return require 'data/Calculation/DateTime/EDATE.php';
}
public function testEDATEtoPHP()
{
Functions::setReturnDateType(Functions::RETURNDATE_PHP_NUMERIC);
$result = DateTime::EDATE('2012-1-26', -1);
Functions::setReturnDateType(Functions::RETURNDATE_EXCEL);
self::assertEquals(1324857600, $result, null, 1E-8);
}
public function testEDATEtoPHPObject()
{
Functions::setReturnDateType(Functions::RETURNDATE_PHP_OBJECT);
$result = DateTime::EDATE('2012-1-26', -1);
Functions::setReturnDateType(Functions::RETURNDATE_EXCEL);
// Must return an object...
self::assertInternalType('object', $result);
// ... of the correct type
self::assertTrue(is_a($result, 'DateTime'));
// ... with the correct value
self::assertEquals($result->format('d-M-Y'), '26-Dec-2011');
}
/**
* @dataProvider providerEOMONTH
*
* @param mixed $expectedResult
*/
public function testEOMONTH($expectedResult, ...$args)
{
$result = DateTime::EOMONTH(...$args);
self::assertEquals($expectedResult, $result, null, 1E-8);
}
public function providerEOMONTH()
{
return require 'data/Calculation/DateTime/EOMONTH.php';
}
public function testEOMONTHtoPHP()
{
Functions::setReturnDateType(Functions::RETURNDATE_PHP_NUMERIC);
$result = DateTime::EOMONTH('2012-1-26', -1);
Functions::setReturnDateType(Functions::RETURNDATE_EXCEL);
self::assertEquals(1325289600, $result, null, 1E-8);
}
public function testEOMONTHtoPHPObject()
{
Functions::setReturnDateType(Functions::RETURNDATE_PHP_OBJECT);
$result = DateTime::EOMONTH('2012-1-26', -1);
Functions::setReturnDateType(Functions::RETURNDATE_EXCEL);
// Must return an object...
self::assertInternalType('object', $result);
// ... of the correct type
self::assertTrue(is_a($result, 'DateTime'));
// ... with the correct value
self::assertEquals($result->format('d-M-Y'), '31-Dec-2011');
}
/**
* @dataProvider providerDATEDIF
*
* @param mixed $expectedResult
*/
public function testDATEDIF($expectedResult, ...$args)
{
$result = DateTime::DATEDIF(...$args);
self::assertEquals($expectedResult, $result, null, 1E-8);
}
public function providerDATEDIF()
{
return require 'data/Calculation/DateTime/DATEDIF.php';
}
/**
* @dataProvider providerDAYS
*
* @param mixed $expectedResult
*/
public function testDAYS($expectedResult, ...$args)
{
$result = DateTime::DAYS(...$args);
self::assertEquals($expectedResult, $result, null, 1E-8);
}
public function providerDAYS()
{
return require 'data/Calculation/DateTime/DAYS.php';
}
/**
* @dataProvider providerDAYS360
*
* @param mixed $expectedResult
*/
public function testDAYS360($expectedResult, ...$args)
{
$result = DateTime::DAYS360(...$args);
self::assertEquals($expectedResult, $result, null, 1E-8);
}
public function providerDAYS360()
{
return require 'data/Calculation/DateTime/DAYS360.php';
}
/**
* @dataProvider providerYEARFRAC
*
* @param mixed $expectedResult
*/
public function testYEARFRAC($expectedResult, ...$args)
{
$result = DateTime::YEARFRAC(...$args);
self::assertEquals($expectedResult, $result, null, 1E-8);
}
public function providerYEARFRAC()
{
return require 'data/Calculation/DateTime/YEARFRAC.php';
}
}

View File

@ -0,0 +1,34 @@
<?php
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\DateTime;
use PhpOffice\PhpSpreadsheet\Calculation\DateTime;
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
use PhpOffice\PhpSpreadsheet\Shared\Date;
use PHPUnit\Framework\TestCase;
class DateDifTest extends TestCase
{
public function setUp()
{
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
Functions::setReturnDateType(Functions::RETURNDATE_EXCEL);
Date::setExcelCalendar(Date::CALENDAR_WINDOWS_1900);
}
/**
* @dataProvider providerDATEDIF
*
* @param mixed $expectedResult
*/
public function testDATEDIF($expectedResult, ...$args)
{
$result = DateTime::DATEDIF(...$args);
$this->assertEquals($expectedResult, $result, '', 1E-8);
}
public function providerDATEDIF()
{
return require 'data/Calculation/DateTime/DATEDIF.php';
}
}

View File

@ -0,0 +1,71 @@
<?php
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\DateTime;
use PhpOffice\PhpSpreadsheet\Calculation\DateTime;
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
use PhpOffice\PhpSpreadsheet\Shared\Date;
use PHPUnit\Framework\TestCase;
class DateTest extends TestCase
{
public function setUp()
{
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
Functions::setReturnDateType(Functions::RETURNDATE_EXCEL);
Date::setExcelCalendar(Date::CALENDAR_WINDOWS_1900);
}
/**
* @dataProvider providerDATE
*
* @param mixed $expectedResult
*/
public function testDATE($expectedResult, ...$args)
{
$result = DateTime::DATE(...$args);
$this->assertEquals($expectedResult, $result, '', 1E-8);
}
public function providerDATE()
{
return require 'data/Calculation/DateTime/DATE.php';
}
public function testDATEtoUnixTimestamp()
{
Functions::setReturnDateType(Functions::RETURNDATE_UNIX_TIMESTAMP);
$result = DateTime::DATE(2012, 1, 31);
$this->assertEquals(1327968000, $result, '', 1E-8);
}
public function testDATEtoDateTimeObject()
{
Functions::setReturnDateType(Functions::RETURNDATE_PHP_DATETIME_OBJECT);
$result = DateTime::DATE(2012, 1, 31);
// Must return an object...
$this->assertInternalType('object', $result);
// ... of the correct type
$this->assertTrue(is_a($result, 'DateTimeInterface'));
// ... with the correct value
$this->assertEquals($result->format('d-M-Y'), '31-Jan-2012');
}
public function testDATEwith1904Calendar()
{
Date::setExcelCalendar(Date::CALENDAR_MAC_1904);
$result = DateTime::DATE(1918, 11, 11);
$this->assertEquals($result, 5428);
}
public function testDATEwith1904CalendarError()
{
Date::setExcelCalendar(Date::CALENDAR_MAC_1904);
$result = DateTime::DATE(1901, 1, 31);
$this->assertEquals($result, '#NUM!');
}
}

View File

@ -0,0 +1,55 @@
<?php
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\DateTime;
use PhpOffice\PhpSpreadsheet\Calculation\DateTime;
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
use PhpOffice\PhpSpreadsheet\Shared\Date;
use PHPUnit\Framework\TestCase;
class DateValueTest extends TestCase
{
public function setUp()
{
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
Functions::setReturnDateType(Functions::RETURNDATE_EXCEL);
Date::setExcelCalendar(Date::CALENDAR_WINDOWS_1900);
}
/**
* @dataProvider providerDATEVALUE
*
* @param mixed $expectedResult
*/
public function testDATEVALUE($expectedResult, ...$args)
{
$result = DateTime::DATEVALUE(...$args);
$this->assertEquals($expectedResult, $result, '', 1E-8);
}
public function providerDATEVALUE()
{
return require 'data/Calculation/DateTime/DATEVALUE.php';
}
public function testDATEVALUEtoUnixTimestamp()
{
Functions::setReturnDateType(Functions::RETURNDATE_UNIX_TIMESTAMP);
$result = DateTime::DATEVALUE('2012-1-31');
$this->assertEquals(1327968000, $result, '', 1E-8);
}
public function testDATEVALUEtoDateTimeObject()
{
Functions::setReturnDateType(Functions::RETURNDATE_PHP_DATETIME_OBJECT);
$result = DateTime::DATEVALUE('2012-1-31');
// Must return an object...
$this->assertInternalType('object', $result);
// ... of the correct type
$this->assertTrue(is_a($result, 'DateTimeInterface'));
// ... with the correct value
$this->assertEquals($result->format('d-M-Y'), '31-Jan-2012');
}
}

View File

@ -0,0 +1,40 @@
<?php
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\DateTime;
use PhpOffice\PhpSpreadsheet\Calculation\DateTime;
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
use PhpOffice\PhpSpreadsheet\Shared\Date;
use PHPUnit\Framework\TestCase;
class DayTest extends TestCase
{
public function setUp()
{
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
Functions::setReturnDateType(Functions::RETURNDATE_EXCEL);
Date::setExcelCalendar(Date::CALENDAR_WINDOWS_1900);
}
/**
* @dataProvider providerDAY
*
* @param mixed $expectedResultExcel
* @param mixed $expectedResultOpenOffice
*/
public function testDAY($expectedResultExcel, $expectedResultOpenOffice, ...$args)
{
$resultExcel = DateTime::DAYOFMONTH(...$args);
$this->assertEquals($expectedResultExcel, $resultExcel, '', 1E-8);
Functions::setCompatibilityMode(Functions::COMPATIBILITY_OPENOFFICE);
$resultOpenOffice = DateTime::DAYOFMONTH(...$args);
$this->assertEquals($expectedResultOpenOffice, $resultOpenOffice, '', 1E-8);
}
public function providerDAY()
{
return require 'data/Calculation/DateTime/DAY.php';
}
}

View File

@ -0,0 +1,34 @@
<?php
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\DateTime;
use PhpOffice\PhpSpreadsheet\Calculation\DateTime;
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
use PhpOffice\PhpSpreadsheet\Shared\Date;
use PHPUnit\Framework\TestCase;
class Days360Test extends TestCase
{
public function setUp()
{
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
Functions::setReturnDateType(Functions::RETURNDATE_EXCEL);
Date::setExcelCalendar(Date::CALENDAR_WINDOWS_1900);
}
/**
* @dataProvider providerDAYS360
*
* @param mixed $expectedResult
*/
public function testDAYS360($expectedResult, ...$args)
{
$result = DateTime::DAYS360(...$args);
$this->assertEquals($expectedResult, $result, '', 1E-8);
}
public function providerDAYS360()
{
return require 'data/Calculation/DateTime/DAYS360.php';
}
}

View File

@ -0,0 +1,34 @@
<?php
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\DateTime;
use PhpOffice\PhpSpreadsheet\Calculation\DateTime;
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
use PhpOffice\PhpSpreadsheet\Shared\Date;
use PHPUnit\Framework\TestCase;
class DaysTest extends TestCase
{
public function setUp()
{
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
Functions::setReturnDateType(Functions::RETURNDATE_EXCEL);
Date::setExcelCalendar(Date::CALENDAR_WINDOWS_1900);
}
/**
* @dataProvider providerDAYS
*
* @param mixed $expectedResult
*/
public function testDAYS($expectedResult, ...$args)
{
$result = DateTime::DAYS(...$args);
$this->assertEquals($expectedResult, $result, '', 1E-8);
}
public function providerDAYS()
{
return require 'data/Calculation/DateTime/DAYS.php';
}
}

View File

@ -0,0 +1,55 @@
<?php
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\DateTime;
use PhpOffice\PhpSpreadsheet\Calculation\DateTime;
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
use PhpOffice\PhpSpreadsheet\Shared\Date;
use PHPUnit\Framework\TestCase;
class EDateTest extends TestCase
{
public function setUp()
{
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
Functions::setReturnDateType(Functions::RETURNDATE_EXCEL);
Date::setExcelCalendar(Date::CALENDAR_WINDOWS_1900);
}
/**
* @dataProvider providerEDATE
*
* @param mixed $expectedResult
*/
public function testEDATE($expectedResult, ...$args)
{
$result = DateTime::EDATE(...$args);
$this->assertEquals($expectedResult, $result, '', 1E-8);
}
public function providerEDATE()
{
return require 'data/Calculation/DateTime/EDATE.php';
}
public function testEDATEtoUnixTimestamp()
{
Functions::setReturnDateType(Functions::RETURNDATE_UNIX_TIMESTAMP);
$result = DateTime::EDATE('2012-1-26', -1);
$this->assertEquals(1324857600, $result, '', 1E-8);
}
public function testEDATEtoDateTimeObject()
{
Functions::setReturnDateType(Functions::RETURNDATE_PHP_DATETIME_OBJECT);
$result = DateTime::EDATE('2012-1-26', -1);
// Must return an object...
$this->assertInternalType('object', $result);
// ... of the correct type
$this->assertTrue(is_a($result, 'DateTimeInterface'));
// ... with the correct value
$this->assertEquals($result->format('d-M-Y'), '26-Dec-2011');
}
}

View File

@ -0,0 +1,55 @@
<?php
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\DateTime;
use PhpOffice\PhpSpreadsheet\Calculation\DateTime;
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
use PhpOffice\PhpSpreadsheet\Shared\Date;
use PHPUnit\Framework\TestCase;
class EoMonthTest extends TestCase
{
public function setUp()
{
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
Functions::setReturnDateType(Functions::RETURNDATE_EXCEL);
Date::setExcelCalendar(Date::CALENDAR_WINDOWS_1900);
}
/**
* @dataProvider providerEOMONTH
*
* @param mixed $expectedResult
*/
public function testEOMONTH($expectedResult, ...$args)
{
$result = DateTime::EOMONTH(...$args);
$this->assertEquals($expectedResult, $result, '', 1E-8);
}
public function providerEOMONTH()
{
return require 'data/Calculation/DateTime/EOMONTH.php';
}
public function testEOMONTHtoUnixTimestamp()
{
Functions::setReturnDateType(Functions::RETURNDATE_UNIX_TIMESTAMP);
$result = DateTime::EOMONTH('2012-1-26', -1);
$this->assertEquals(1325289600, $result, '', 1E-8);
}
public function testEOMONTHtoDateTimeObject()
{
Functions::setReturnDateType(Functions::RETURNDATE_PHP_DATETIME_OBJECT);
$result = DateTime::EOMONTH('2012-1-26', -1);
// Must return an object...
$this->assertInternalType('object', $result);
// ... of the correct type
$this->assertTrue(is_a($result, 'DateTimeInterface'));
// ... with the correct value
$this->assertEquals($result->format('d-M-Y'), '31-Dec-2011');
}
}

View File

@ -0,0 +1,34 @@
<?php
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\DateTime;
use PhpOffice\PhpSpreadsheet\Calculation\DateTime;
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
use PhpOffice\PhpSpreadsheet\Shared\Date;
use PHPUnit\Framework\TestCase;
class HourTest extends TestCase
{
public function setUp()
{
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
Functions::setReturnDateType(Functions::RETURNDATE_EXCEL);
Date::setExcelCalendar(Date::CALENDAR_WINDOWS_1900);
}
/**
* @dataProvider providerHOUR
*
* @param mixed $expectedResult
*/
public function testHOUR($expectedResult, ...$args)
{
$result = DateTime::HOUROFDAY(...$args);
$this->assertEquals($expectedResult, $result, '', 1E-8);
}
public function providerHOUR()
{
return require 'data/Calculation/DateTime/HOUR.php';
}
}

View File

@ -0,0 +1,35 @@
<?php
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\DateTime;
use PhpOffice\PhpSpreadsheet\Calculation\DateTime;
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
use PhpOffice\PhpSpreadsheet\Shared\Date;
use PHPUnit\Framework\TestCase;
class IsoWeekNumTest extends TestCase
{
public function setUp()
{
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
Functions::setReturnDateType(Functions::RETURNDATE_EXCEL);
Date::setExcelCalendar(Date::CALENDAR_WINDOWS_1900);
}
/**
* @dataProvider providerISOWEEKNUM
*
* @param mixed $expectedResult
* @param mixed $dateValue
*/
public function testISOWEEKNUM($expectedResult, $dateValue)
{
$result = DateTime::ISOWEEKNUM($dateValue);
$this->assertEquals($expectedResult, $result, '', 1E-8);
}
public function providerISOWEEKNUM()
{
return require 'data/Calculation/DateTime/ISOWEEKNUM.php';
}
}

View File

@ -0,0 +1,34 @@
<?php
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\DateTime;
use PhpOffice\PhpSpreadsheet\Calculation\DateTime;
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
use PhpOffice\PhpSpreadsheet\Shared\Date;
use PHPUnit\Framework\TestCase;
class MinuteTest extends TestCase
{
public function setUp()
{
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
Functions::setReturnDateType(Functions::RETURNDATE_EXCEL);
Date::setExcelCalendar(Date::CALENDAR_WINDOWS_1900);
}
/**
* @dataProvider providerMINUTE
*
* @param mixed $expectedResult
*/
public function testMINUTE($expectedResult, ...$args)
{
$result = DateTime::MINUTE(...$args);
$this->assertEquals($expectedResult, $result, '', 1E-8);
}
public function providerMINUTE()
{
return require 'data/Calculation/DateTime/MINUTE.php';
}
}

View File

@ -0,0 +1,34 @@
<?php
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\DateTime;
use PhpOffice\PhpSpreadsheet\Calculation\DateTime;
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
use PhpOffice\PhpSpreadsheet\Shared\Date;
use PHPUnit\Framework\TestCase;
class MonthTest extends TestCase
{
public function setUp()
{
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
Functions::setReturnDateType(Functions::RETURNDATE_EXCEL);
Date::setExcelCalendar(Date::CALENDAR_WINDOWS_1900);
}
/**
* @dataProvider providerMONTH
*
* @param mixed $expectedResult
*/
public function testMONTH($expectedResult, ...$args)
{
$result = DateTime::MONTHOFYEAR(...$args);
$this->assertEquals($expectedResult, $result, '', 1E-8);
}
public function providerMONTH()
{
return require 'data/Calculation/DateTime/MONTH.php';
}
}

View File

@ -0,0 +1,34 @@
<?php
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\DateTime;
use PhpOffice\PhpSpreadsheet\Calculation\DateTime;
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
use PhpOffice\PhpSpreadsheet\Shared\Date;
use PHPUnit\Framework\TestCase;
class NetworkDaysTest extends TestCase
{
public function setUp()
{
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
Functions::setReturnDateType(Functions::RETURNDATE_EXCEL);
Date::setExcelCalendar(Date::CALENDAR_WINDOWS_1900);
}
/**
* @dataProvider providerNETWORKDAYS
*
* @param mixed $expectedResult
*/
public function testNETWORKDAYS($expectedResult, ...$args)
{
$result = DateTime::NETWORKDAYS(...$args);
$this->assertEquals($expectedResult, $result, '', 1E-8);
}
public function providerNETWORKDAYS()
{
return require 'data/Calculation/DateTime/NETWORKDAYS.php';
}
}

View File

@ -0,0 +1,34 @@
<?php
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\DateTime;
use PhpOffice\PhpSpreadsheet\Calculation\DateTime;
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
use PhpOffice\PhpSpreadsheet\Shared\Date;
use PHPUnit\Framework\TestCase;
class SecondTest extends TestCase
{
public function setUp()
{
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
Functions::setReturnDateType(Functions::RETURNDATE_EXCEL);
Date::setExcelCalendar(Date::CALENDAR_WINDOWS_1900);
}
/**
* @dataProvider providerSECOND
*
* @param mixed $expectedResult
*/
public function testSECOND($expectedResult, ...$args)
{
$result = DateTime::SECOND(...$args);
$this->assertEquals($expectedResult, $result, '', 1E-8);
}
public function providerSECOND()
{
return require 'data/Calculation/DateTime/SECOND.php';
}
}

View File

@ -0,0 +1,55 @@
<?php
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\DateTime;
use PhpOffice\PhpSpreadsheet\Calculation\DateTime;
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
use PhpOffice\PhpSpreadsheet\Shared\Date;
use PHPUnit\Framework\TestCase;
class TimeTest extends TestCase
{
public function setUp()
{
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
Functions::setReturnDateType(Functions::RETURNDATE_EXCEL);
Date::setExcelCalendar(Date::CALENDAR_WINDOWS_1900);
}
/**
* @dataProvider providerTIME
*
* @param mixed $expectedResult
*/
public function testTIME($expectedResult, ...$args)
{
$result = DateTime::TIME(...$args);
$this->assertEquals($expectedResult, $result, '', 1E-8);
}
public function providerTIME()
{
return require 'data/Calculation/DateTime/TIME.php';
}
public function testTIMEtoUnixTimestamp()
{
Functions::setReturnDateType(Functions::RETURNDATE_PHP_NUMERIC);
$result = DateTime::TIME(7, 30, 20);
$this->assertEquals(27020, $result, '', 1E-8);
}
public function testTIMEtoDateTimeObject()
{
Functions::setReturnDateType(Functions::RETURNDATE_PHP_OBJECT);
$result = DateTime::TIME(7, 30, 20);
// Must return an object...
$this->assertInternalType('object', $result);
// ... of the correct type
$this->assertTrue(is_a($result, 'DateTimeInterface'));
// ... with the correct value
$this->assertEquals($result->format('H:i:s'), '07:30:20');
}
}

View File

@ -0,0 +1,55 @@
<?php
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\DateTime;
use PhpOffice\PhpSpreadsheet\Calculation\DateTime;
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
use PhpOffice\PhpSpreadsheet\Shared\Date;
use PHPUnit\Framework\TestCase;
class TimeValueTest extends TestCase
{
public function setUp()
{
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
Functions::setReturnDateType(Functions::RETURNDATE_EXCEL);
Date::setExcelCalendar(Date::CALENDAR_WINDOWS_1900);
}
/**
* @dataProvider providerTIMEVALUE
*
* @param mixed $expectedResult
*/
public function testTIMEVALUE($expectedResult, ...$args)
{
$result = DateTime::TIMEVALUE(...$args);
$this->assertEquals($expectedResult, $result, '', 1E-8);
}
public function providerTIMEVALUE()
{
return require 'data/Calculation/DateTime/TIMEVALUE.php';
}
public function testTIMEVALUEtoUnixTimestamp()
{
Functions::setReturnDateType(Functions::RETURNDATE_UNIX_TIMESTAMP);
$result = DateTime::TIMEVALUE('7:30:20');
$this->assertEquals(23420, $result, '', 1E-8);
}
public function testTIMEVALUEtoDateTimeObject()
{
Functions::setReturnDateType(Functions::RETURNDATE_PHP_DATETIME_OBJECT);
$result = DateTime::TIMEVALUE('7:30:20');
// Must return an object...
$this->assertInternalType('object', $result);
// ... of the correct type
$this->assertTrue(is_a($result, 'DateTimeInterface'));
// ... with the correct value
$this->assertEquals($result->format('H:i:s'), '07:30:20');
}
}

View File

@ -0,0 +1,34 @@
<?php
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\DateTime;
use PhpOffice\PhpSpreadsheet\Calculation\DateTime;
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
use PhpOffice\PhpSpreadsheet\Shared\Date;
use PHPUnit\Framework\TestCase;
class WeekDayTest extends TestCase
{
public function setUp()
{
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
Functions::setReturnDateType(Functions::RETURNDATE_EXCEL);
Date::setExcelCalendar(Date::CALENDAR_WINDOWS_1900);
}
/**
* @dataProvider providerWEEKDAY
*
* @param mixed $expectedResult
*/
public function testWEEKDAY($expectedResult, ...$args)
{
$result = DateTime::WEEKDAY(...$args);
$this->assertEquals($expectedResult, $result, '', 1E-8);
}
public function providerWEEKDAY()
{
return require 'data/Calculation/DateTime/WEEKDAY.php';
}
}

View File

@ -0,0 +1,34 @@
<?php
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\DateTime;
use PhpOffice\PhpSpreadsheet\Calculation\DateTime;
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
use PhpOffice\PhpSpreadsheet\Shared\Date;
use PHPUnit\Framework\TestCase;
class WeekNumTest extends TestCase
{
public function setUp()
{
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
Functions::setReturnDateType(Functions::RETURNDATE_EXCEL);
Date::setExcelCalendar(Date::CALENDAR_WINDOWS_1900);
}
/**
* @dataProvider providerWEEKNUM
*
* @param mixed $expectedResult
*/
public function testWEEKNUM($expectedResult, ...$args)
{
$result = DateTime::WEEKNUM(...$args);
$this->assertEquals($expectedResult, $result, '', 1E-8);
}
public function providerWEEKNUM()
{
return require 'data/Calculation/DateTime/WEEKNUM.php';
}
}

View File

@ -0,0 +1,34 @@
<?php
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\DateTime;
use PhpOffice\PhpSpreadsheet\Calculation\DateTime;
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
use PhpOffice\PhpSpreadsheet\Shared\Date;
use PHPUnit\Framework\TestCase;
class WorkDayTest extends TestCase
{
public function setUp()
{
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
Functions::setReturnDateType(Functions::RETURNDATE_EXCEL);
Date::setExcelCalendar(Date::CALENDAR_WINDOWS_1900);
}
/**
* @dataProvider providerWORKDAY
*
* @param mixed $expectedResult
*/
public function testWORKDAY($expectedResult, ...$args)
{
$result = DateTime::WORKDAY(...$args);
$this->assertEquals($expectedResult, $result, '', 1E-8);
}
public function providerWORKDAY()
{
return require 'data/Calculation/DateTime/WORKDAY.php';
}
}

View File

@ -0,0 +1,34 @@
<?php
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\DateTime;
use PhpOffice\PhpSpreadsheet\Calculation\DateTime;
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
use PhpOffice\PhpSpreadsheet\Shared\Date;
use PHPUnit\Framework\TestCase;
class YearFracTest extends TestCase
{
public function setUp()
{
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
Functions::setReturnDateType(Functions::RETURNDATE_EXCEL);
Date::setExcelCalendar(Date::CALENDAR_WINDOWS_1900);
}
/**
* @dataProvider providerYEARFRAC
*
* @param mixed $expectedResult
*/
public function testYEARFRAC($expectedResult, ...$args)
{
$result = DateTime::YEARFRAC(...$args);
$this->assertEquals($expectedResult, $result, '', 1E-8);
}
public function providerYEARFRAC()
{
return require 'data/Calculation/DateTime/YEARFRAC.php';
}
}

View File

@ -0,0 +1,34 @@
<?php
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\DateTime;
use PhpOffice\PhpSpreadsheet\Calculation\DateTime;
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
use PhpOffice\PhpSpreadsheet\Shared\Date;
use PHPUnit\Framework\TestCase;
class YearTest extends TestCase
{
public function setUp()
{
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
Functions::setReturnDateType(Functions::RETURNDATE_EXCEL);
Date::setExcelCalendar(Date::CALENDAR_WINDOWS_1900);
}
/**
* @dataProvider providerYEAR
*
* @param mixed $expectedResult
*/
public function testYEAR($expectedResult, ...$args)
{
$result = DateTime::YEAR(...$args);
$this->assertEquals($expectedResult, $result, '', 1E-8);
}
public function providerYEAR()
{
return require 'data/Calculation/DateTime/YEAR.php';
}
}

View File

@ -21,7 +21,7 @@ class AveDevTest extends TestCase
public function testAVEDEV($expectedResult, ...$args)
{
$result = Statistical::AVEDEV(...$args);
self::assertEquals($expectedResult, $result, '', 1E-12);
$this->assertEquals($expectedResult, $result, '', 1E-12);
}
public function providerAVEDEV()

View File

@ -21,7 +21,7 @@ class AverageATest extends TestCase
public function testAVERAGEA($expectedResult, ...$args)
{
$result = Statistical::AVERAGEA(...$args);
self::assertEquals($expectedResult, $result, '', 1E-12);
$this->assertEquals($expectedResult, $result, '', 1E-12);
}
public function providerAVERAGEA()

View File

@ -21,7 +21,7 @@ class AverageIfTest extends TestCase
public function testAVERAGEIF($expectedResult, ...$args)
{
$result = Statistical::AVERAGEIF(...$args);
self::assertEquals($expectedResult, $result, '', 1E-12);
$this->assertEquals($expectedResult, $result, '', 1E-12);
}
public function providerAVERAGEIF()

View File

@ -21,7 +21,7 @@ class AverageTest extends TestCase
public function testAVERAGE($expectedResult, ...$args)
{
$result = Statistical::AVERAGE(...$args);
self::assertEquals($expectedResult, $result, '', 1E-12);
$this->assertEquals($expectedResult, $result, '', 1E-12);
}
public function providerAVERAGE()

View File

@ -21,7 +21,7 @@ class BetaDistTest extends TestCase
public function testBETADIST($expectedResult, ...$args)
{
$result = Statistical::BETADIST(...$args);
self::assertEquals($expectedResult, $result, '', 1E-12);
$this->assertEquals($expectedResult, $result, '', 1E-12);
}
public function providerBETADIST()

View File

@ -21,7 +21,7 @@ class BetaInvTest extends TestCase
public function testBETAINV($expectedResult, ...$args)
{
$result = Statistical::BETAINV(...$args);
self::assertEquals($expectedResult, $result, '', 1E-12);
$this->assertEquals($expectedResult, $result, '', 1E-12);
}
public function providerBETAINV()

View File

@ -21,7 +21,7 @@ class BinomDistTest extends TestCase
public function testBINOMDIST($expectedResult, ...$args)
{
$result = Statistical::BINOMDIST(...$args);
self::assertEquals($expectedResult, $result, '', 1E-12);
$this->assertEquals($expectedResult, $result, '', 1E-12);
}
public function providerBINOMDIST()

View File

@ -21,7 +21,7 @@ class ChiDistTest extends TestCase
public function testCHIDIST($expectedResult, ...$args)
{
$result = Statistical::CHIDIST(...$args);
self::assertEquals($expectedResult, $result, '', 1E-12);
$this->assertEquals($expectedResult, $result, '', 1E-12);
}
public function providerCHIDIST()

View File

@ -21,7 +21,7 @@ class ChiInvTest extends TestCase
public function testCHIINV($expectedResult, ...$args)
{
$result = Statistical::CHIINV(...$args);
self::assertEquals($expectedResult, $result, '', 1E-12);
$this->assertEquals($expectedResult, $result, '', 1E-12);
}
public function providerCHIINV()

View File

@ -21,7 +21,7 @@ class ConfidenceTest extends TestCase
public function testCONFIDENCE($expectedResult, ...$args)
{
$result = Statistical::CONFIDENCE(...$args);
self::assertEquals($expectedResult, $result, '', 1E-12);
$this->assertEquals($expectedResult, $result, '', 1E-12);
}
public function providerCONFIDENCE()

View File

@ -21,7 +21,7 @@ class CorrelTest extends TestCase
public function testCORREL($expectedResult, array $xargs, array $yargs)
{
$result = Statistical::CORREL($xargs, $yargs);
self::assertEquals($expectedResult, $result, '', 1E-12);
$this->assertEquals($expectedResult, $result, '', 1E-12);
}
public function providerCORREL()

View File

@ -21,7 +21,7 @@ class CountATest extends TestCase
public function testCOUNTA($expectedResult, ...$args)
{
$result = Statistical::COUNTA(...$args);
self::assertEquals($expectedResult, $result, '', 1E-12);
$this->assertEquals($expectedResult, $result, '', 1E-12);
}
public function providerCOUNTA()

View File

@ -21,7 +21,7 @@ class CountBlankTest extends TestCase
public function testCOUNTBLANK($expectedResult, ...$args)
{
$result = Statistical::COUNTBLANK(...$args);
self::assertEquals($expectedResult, $result, '', 1E-12);
$this->assertEquals($expectedResult, $result, '', 1E-12);
}
public function providerCOUNTBLANK()

View File

@ -21,7 +21,7 @@ class CountIfTest extends TestCase
public function testCOUNTIF($expectedResult, ...$args)
{
$result = Statistical::COUNTIF(...$args);
self::assertEquals($expectedResult, $result, '', 1E-12);
$this->assertEquals($expectedResult, $result, '', 1E-12);
}
public function providerCOUNTIF()

View File

@ -21,7 +21,7 @@ class CountIfsTest extends TestCase
public function testCOUNTIFS($expectedResult, ...$args)
{
$result = Statistical::COUNTIFS(...$args);
self::assertEquals($expectedResult, $result, '', 1E-12);
$this->assertEquals($expectedResult, $result, '', 1E-12);
}
public function providerCOUNTIFS()

View File

@ -21,7 +21,7 @@ class CountTest extends TestCase
public function testBasicCOUNT($expectedResult, ...$args)
{
$result = Statistical::COUNT(...$args);
self::assertEquals($expectedResult, $result, '', 1E-12);
$this->assertEquals($expectedResult, $result, '', 1E-12);
}
public function providerBasicCOUNT()
@ -37,7 +37,7 @@ class CountTest extends TestCase
public function testExcelCOUNT($expectedResult, ...$args)
{
$result = Statistical::COUNT(...$args);
self::assertEquals($expectedResult, $result, '', 1E-12);
$this->assertEquals($expectedResult, $result, '', 1E-12);
}
public function providerExcelCOUNT()
@ -55,7 +55,7 @@ class CountTest extends TestCase
Functions::setCompatibilityMode(Functions::COMPATIBILITY_OPENOFFICE);
$result = Statistical::COUNT(...$args);
self::assertEquals($expectedResult, $result, '', 1E-12);
$this->assertEquals($expectedResult, $result, '', 1E-12);
}
public function providerOpenOfficeCOUNT()
@ -73,7 +73,7 @@ class CountTest extends TestCase
Functions::setCompatibilityMode(Functions::COMPATIBILITY_GNUMERIC);
$result = Statistical::COUNT(...$args);
self::assertEquals($expectedResult, $result, '', 1E-12);
$this->assertEquals($expectedResult, $result, '', 1E-12);
}
public function providerGnumericCOUNT()

View File

@ -21,7 +21,7 @@ class CovarTest extends TestCase
public function testCOVAR($expectedResult, ...$args)
{
$result = Statistical::COVAR(...$args);
self::assertEquals($expectedResult, $result, '', 1E-12);
$this->assertEquals($expectedResult, $result, '', 1E-12);
}
public function providerCOVAR()

View File

@ -21,7 +21,7 @@ class ForecastTest extends TestCase
public function testFORECAST($expectedResult, ...$args)
{
$result = Statistical::FORECAST(...$args);
self::assertEquals($expectedResult, $result, '', 1E-12);
$this->assertEquals($expectedResult, $result, '', 1E-12);
}
public function providerFORECAST()

View File

@ -21,7 +21,7 @@ class InterceptTest extends TestCase
public function testINTERCEPT($expectedResult, array $xargs, array $yargs)
{
$result = Statistical::INTERCEPT($xargs, $yargs);
self::assertEquals($expectedResult, $result, '', 1E-12);
$this->assertEquals($expectedResult, $result, '', 1E-12);
}
public function providerINTERCEPT()

View File

@ -21,7 +21,7 @@ class MaxIfsTest extends TestCase
public function testMAXIFS($expectedResult, ...$args)
{
$result = Statistical::MAXIFS(...$args);
self::assertEquals($expectedResult, $result, '', 1E-12);
$this->assertEquals($expectedResult, $result, '', 1E-12);
}
public function providerMAXIFS()

View File

@ -21,7 +21,7 @@ class MinIfsTest extends TestCase
public function testMINIFS($expectedResult, ...$args)
{
$result = Statistical::MINIFS(...$args);
self::assertEquals($expectedResult, $result, '', 1E-12);
$this->assertEquals($expectedResult, $result, '', 1E-12);
}
public function providerMINIFS()

View File

@ -21,7 +21,7 @@ class PermutTest extends TestCase
public function testPERMUT($expectedResult, ...$args)
{
$result = Statistical::PERMUT(...$args);
self::assertEquals($expectedResult, $result, '', 1E-12);
$this->assertEquals($expectedResult, $result, '', 1E-12);
}
public function providerPERMUT()

View File

@ -21,7 +21,7 @@ class RsqTest extends TestCase
public function testRSQ($expectedResult, array $xargs, array $yargs)
{
$result = Statistical::RSQ($xargs, $yargs);
self::assertEquals($expectedResult, $result, '', 1E-12);
$this->assertEquals($expectedResult, $result, '', 1E-12);
}
public function providerRSQ()

View File

@ -21,7 +21,7 @@ class SlopeTest extends TestCase
public function testSLOPE($expectedResult, array $xargs, array $yargs)
{
$result = Statistical::SLOPE($xargs, $yargs);
self::assertEquals($expectedResult, $result, '', 1E-12);
$this->assertEquals($expectedResult, $result, '', 1E-12);
}
public function providerSLOPE()

View File

@ -21,7 +21,7 @@ class SteyxTest extends TestCase
public function testSTEYX($expectedResult, array $xargs, array $yargs)
{
$result = Statistical::STEYX($xargs, $yargs);
self::assertEquals($expectedResult, $result, '', 1E-12);
$this->assertEquals($expectedResult, $result, '', 1E-12);
}
public function providerSTEYX()

View File

@ -5,485 +5,329 @@
return [
[
6890,
18,
11,
11,
18, 11, 11,
],
// Excel 1900 Calendar Base Date
[
1,
1900,
1,
1,
1900, 1, 1,
],
// Day before Excel mythical 1900 leap day
[
59,
1900,
2,
28,
1900, 2, 28,
],
// Excel mythical 1900 leap day
[
60,
1900,
2,
29,
1900, 2, 29,
],
// Day after Excel mythical 1900 leap day
[
61,
1900,
3,
1,
],
// Day after Excel mythical 1900 leap day
61,
1900, 3, 1,
],
// Day after Excel actual 1904 leap day
[
713,
1901,
12,
13,
1901, 12, 13,
],
// PHP 32-bit Earliest Date
// PHP 32-bit Earliest Date (unix timestamp)
[
714,
1901,
12,
14,
1901, 12, 14,
],
[
1461,
1903,
12,
31,
1903, 12, 31,
],
// Excel 1904 Calendar Base Date
[
1462,
1904,
1,
1,
1904, 1, 1,
],
[
1463,
1904,
1,
2,
1904, 1, 2,
],
[
22269,
1960,
12,
19,
1960, 12, 19,
],
// PHP Base Date
// PHP (unix timestamp) Base Date
[
25569,
1970,
1,
1,
1970, 1, 1,
],
[
30292,
1982,
12,
7,
1982, 12, 7,
],
[
39611,
2008,
6,
12,
2008, 6, 12,
],
// PHP 32-bit Latest Date
// PHP (unix timestamp) 32-bit Latest Date
[
50424,
2038,
1,
19,
2038, 1, 19,
],
// Day after PHP 32-bit Latest Date
// Day after PHP (unix timestamp) 32-bit Latest Date
[
50425,
2038,
1,
20,
2038, 1, 20,
],
[
39448,
2008,
1,
1,
2008, 1, 1,
],
[
39447,
2008,
1,
null,
2008, 1, null,
],
[
39446,
2008,
1,
-1,
2008, 1, -1,
],
[
39417,
2008,
1,
-30,
2008, 1, -30,
],
[
39416,
2008,
1,
-31,
2008, 1, -31,
],
[
39082,
2008,
1,
-365,
2008, 1, -365,
],
[
39508,
2008,
3,
1,
2008, 3, 1,
],
[
39507,
2008,
3,
null,
2008, 3, null,
],
[
39506,
2008,
3,
-1,
2008, 3, -1,
],
[
39142,
2008,
3,
-365,
2008, 3, -365,
],
[
39417,
2008,
null,
1,
2008, null, 1,
],
[
39387,
2008,
-1,
1,
2008, -1, 1,
],
[
39083,
2008,
-11,
1,
2008, -11, 1,
],
[
39052,
2008,
-12,
1,
2008, -12, 1,
],
[
39022,
2008,
-13,
1,
2008, -13, 1,
],
[
39051,
2008,
-13,
30,
2008, -13, 30,
],
[
39021,
2008,
-13,
null,
2008, -13, null,
],
[
38991,
2008,
-13,
-30,
2008, -13, -30,
],
[
38990,
2008,
-13,
-31,
2008, -13, -31,
],
[
39814,
2008,
13,
1,
2008, 13, 1,
],
[
39507,
2007,
15,
null,
2007, 15, null,
],
[
40210,
2008,
26,
1,
2008, 26, 1,
],
[
40199,
2008,
26,
-10,
2008, 26, -10,
],
[
38686,
2008,
-26,
61,
2008, -26, 61,
],
[
39641,
2010,
-15,
-50,
2010, -15, -50,
],
[
39741,
2010,
-15,
50,
2010, -15, 50,
],
[
40552,
2010,
15,
-50,
2010, 15, -50,
],
[
40652,
2010,
15,
50,
2010, 15, 50,
],
[
40179,
2010,
1.5,
1,
2010, 1.5, 1,
],
[
40178,
2010,
1.5,
0,
2010, 1.5, 0,
],
[
40148,
2010,
0,
1.5,
2010, 0, 1.5,
],
[
40179,
2010,
1,
1.5,
2010, 1, 1.5,
],
[
41075,
2012,
6,
15,
2012, 6, 15,
],
[
41060,
2012,
6,
null,
2012, 6, null,
],
[
40892,
2012,
null,
15,
2012, null, 15,
],
[
167,
null,
6,
15,
null, 6, 15,
],
[
3819,
10,
6,
15,
10, 6, 15,
],
[
3622,
10,
null,
null,
10, null, null,
],
[
274,
null,
10,
null,
null, 10, null,
],
[
'#NUM!',
null,
null,
10,
null, null, 10,
],
[
'#NUM!',
-20,
null,
null,
-20, null, null,
],
[
'#NUM!',
-20,
6,
15,
-20, 6, 15,
],
// Excel Maximum Date
[
2958465,
9999,
12,
31,
9999, 12, 31,
],
// Exceeded Excel Maximum Date
[
'#NUM!',
10000,
1,
1,
10000, 1, 1,
],
[
39670,
2008,
8,
10,
2008, 8, 10,
],
[
39813,
2008,
12,
31,
2008, 12, 31,
],
[
39692,
2008,
8,
32,
2008, 8, 32,
],
[
39844,
2008,
13,
31,
2008, 13, 31,
],
[
39813,
2009,
1,
0,
2009, 1, 0,
],
[
39812,
2009,
1,
-1,
2009, 1, -1,
],
[
39782,
2009,
0,
0,
2009, 0, 0,
],
[
39781,
2009,
0,
-1,
2009, 0, -1,
],
[
39752,
2009,
-1,
0,
2009, -1, 0,
],
[
39751,
2009,
-1,
-1,
2009, -1, -1,
],
[
40146,
2010,
0,
-1,
2010, 0, -1,
],
[
40329,
2010,
5,
31,
2010, 5, 31,
],
// MS Excel will fail with a #VALUE return, but PhpSpreadsheet can parse this date
[
40199,
2010,
1,
'21st',
2010, 1, '21st',
],
// MS Excel will fail with a #VALUE return, but PhpSpreadsheet can parse this date
[
40258,
2010,
'March',
'21st',
2010, 'March', '21st',
],
// MS Excel will fail with a #VALUE return, but PhpSpreadsheet can parse this date
[
40258,
2010,
'March',
21,
2010, 'March', 21,
],
[
'#VALUE!',
'ABC',
1,
21,
'ABC', 1, 21,
],
[
'#VALUE!',
2010,
'DEF',
21,
2010, 'DEF', 21,
],
[
'#VALUE!',
2010,
3,
'GHI',
2010, 3, 'GHI',
],
];

View File

@ -3,134 +3,90 @@
return [
[
0.75776620370400005,
18,
11,
11,
18, 11, 11,
],
[
0.26047453703700002,
6,
15,
5,
6, 15, 5,
],
[
0.52094907407400004,
12,
30,
10,
12, 30, 10,
],
[
0.78153935185199996,
18,
45,
25,
18, 45, 25,
],
[
0.64780092592600003,
15,
32,
50,
15, 32, 50,
],
[
0.50070601851899998,
12,
null,
61,
12, null, 61,
],
[
0.45832175925899998,
11,
null,
-1,
11, null, -1,
],
[
0.41589120370400001,
10,
null,
-67,
10, null, -67,
],
[
0.58478009259300001,
13,
62,
5,
13, 62, 5,
],
[
0.31964120370400001,
9,
-80,
17,
9, -80, 17,
],
[
0.22083333333300001,
8,
-162,
null,
8, -162, null,
],
[
'#NUM!',
2,
-120,
-1,
2, -120, -1,
],
[
0.0,
2,
-120,
null,
2, -120, null,
],
[
1.1574074E-5,
2,
-120,
1,
2, -120, 1,
],
[
0.50071759259299997,
36,
1,
2,
36, 1, 2,
],
[
'#NUM!',
-1,
2,
3,
-1, 2, 3,
],
[
0.001030092593,
-1,
61,
29,
-1, 61, 29,
],
[
0.0,
-1,
61,
-60,
-1, 61, -60,
],
[
'#VALUE!',
'A',
null,
null,
'A', null, null,
],
[
0.49930555555599998,
11,
59,
0,
11, 59, 0,
],
[
0.5,
12,
0,
0,
12, 0, 0,
],
[
0.70011574074100003,
16,
48,
10,
16, 48, 10,
],
];

View File

@ -7,13 +7,11 @@ return [
],
[
4,
'24-Oct-1968',
2,
'24-Oct-1968', 2,
],
[
3,
'24-Oct-1968',
3,
'24-Oct-1968', 3,
],
[
4,
@ -21,13 +19,11 @@ return [
],
[
3,
'2000-06-14',
2,
'2000-06-14', 2,
],
[
2,
'2000-06-14',
3,
'2000-06-14', 3,
],
[
4,
@ -35,13 +31,11 @@ return [
],
[
3,
'1996-07-24',
2,
'1996-07-24', 2,
],
[
2,
'1996-07-24',
3,
'1996-07-24', 3,
],
[
7,
@ -49,13 +43,11 @@ return [
],
[
6,
'1996-07-27',
2,
'1996-07-27', 2,
],
[
5,
'1996-07-27',
3,
'1996-07-27', 3,
],
[
1,
@ -63,13 +55,11 @@ return [
],
[
7,
'1977-7-31',
2,
'1977-7-31', 2,
],
[
6,
'1977-7-31',
3,
'1977-7-31', 3,
],
[
2,
@ -77,18 +67,15 @@ return [
],
[
1,
'1977-8-1',
2,
'1977-8-1', 2,
],
[
0,
'1977-8-1',
3,
'1977-8-1', 3,
],
[
7,
'1900-2-5',
2,
'1900-2-5', 2,
],
[
4,
@ -100,23 +87,19 @@ return [
],
[
5,
38093,
2,
38093, 2,
],
[
4,
38093,
3,
38093, 3,
],
[
'#VALUE!',
'3/7/1977',
'A',
'3/7/1977', 'A',
],
[
'#NUM!',
'3/7/1977',
0,
'3/7/1977', 0,
],
[
'#VALUE!',