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