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;
|
2016-05-19 06:49:09 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Class DateTimeTest
|
|
|
|
*/
|
2016-03-22 14:35:50 +00:00
|
|
|
class DateTimeTest extends \PHPUnit_Framework_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
|
|
|
|
*/
|
2015-05-17 13:00:02 +00:00
|
|
|
public function testDATE()
|
|
|
|
{
|
|
|
|
$args = func_get_args();
|
|
|
|
$expectedResult = array_pop($args);
|
2016-08-16 15:33:57 +00:00
|
|
|
$result = call_user_func_array([DateTime::class, 'DATE'], $args);
|
2015-05-17 13:00:02 +00:00
|
|
|
$this->assertEquals($expectedResult, $result, null, 1E-8);
|
|
|
|
}
|
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);
|
2015-05-17 13:00:02 +00:00
|
|
|
$this->assertEquals(1327968000, $result, null, 1E-8);
|
|
|
|
}
|
|
|
|
|
|
|
|
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...
|
|
|
|
$this->assertTrue(is_object($result));
|
|
|
|
// ... of the correct type
|
2015-05-17 17:26:34 +00:00
|
|
|
$this->assertTrue(is_a($result, 'DateTime'));
|
2012-07-31 20:56:11 +00:00
|
|
|
// ... with the correct value
|
2015-05-17 17:26:34 +00:00
|
|
|
$this->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);
|
2015-05-17 17:26:34 +00:00
|
|
|
$this->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);
|
2015-05-17 17:26:34 +00:00
|
|
|
$this->assertEquals($result, '#NUM!');
|
2015-05-17 13:00:02 +00:00
|
|
|
}
|
2012-07-31 20:56:11 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider providerDATEVALUE
|
|
|
|
*/
|
2015-05-17 13:00:02 +00:00
|
|
|
public function testDATEVALUE()
|
|
|
|
{
|
|
|
|
$args = func_get_args();
|
|
|
|
$expectedResult = array_pop($args);
|
2016-08-16 15:33:57 +00:00
|
|
|
$result = call_user_func_array([DateTime::class, 'DATEVALUE'], $args);
|
2015-05-17 13:00:02 +00:00
|
|
|
$this->assertEquals($expectedResult, $result, null, 1E-8);
|
|
|
|
}
|
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);
|
2015-05-17 13:00:02 +00:00
|
|
|
$this->assertEquals(1327968000, $result, null, 1E-8);
|
|
|
|
}
|
|
|
|
|
|
|
|
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...
|
|
|
|
$this->assertTrue(is_object($result));
|
|
|
|
// ... of the correct type
|
2015-05-17 17:26:34 +00:00
|
|
|
$this->assertTrue(is_a($result, 'DateTime'));
|
2012-07-31 20:56:11 +00:00
|
|
|
// ... with the correct value
|
2015-05-17 17:26:34 +00:00
|
|
|
$this->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
|
|
|
|
*/
|
2015-05-17 13:00:02 +00:00
|
|
|
public function testYEAR()
|
|
|
|
{
|
|
|
|
$args = func_get_args();
|
|
|
|
$expectedResult = array_pop($args);
|
2016-08-16 15:33:57 +00:00
|
|
|
$result = call_user_func_array([DateTime::class, 'YEAR'], $args);
|
2015-05-17 13:00:02 +00:00
|
|
|
$this->assertEquals($expectedResult, $result, null, 1E-8);
|
|
|
|
}
|
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
|
|
|
|
*/
|
2015-05-17 13:00:02 +00:00
|
|
|
public function testMONTH()
|
|
|
|
{
|
|
|
|
$args = func_get_args();
|
|
|
|
$expectedResult = array_pop($args);
|
2016-08-16 15:33:57 +00:00
|
|
|
$result = call_user_func_array([DateTime::class, 'MONTHOFYEAR'], $args);
|
2015-05-17 13:00:02 +00:00
|
|
|
$this->assertEquals($expectedResult, $result, null, 1E-8);
|
|
|
|
}
|
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
|
2016-05-19 10:31:40 +00:00
|
|
|
* @group fail19
|
2012-07-31 20:56:11 +00:00
|
|
|
*/
|
2015-05-17 13:00:02 +00:00
|
|
|
public function testWEEKNUM()
|
|
|
|
{
|
2016-08-14 04:32:43 +00:00
|
|
|
$this->markTestIncomplete('TODO: This test should be fixed');
|
|
|
|
|
2015-05-17 13:00:02 +00:00
|
|
|
$args = func_get_args();
|
|
|
|
$expectedResult = array_pop($args);
|
2016-08-16 15:33:57 +00:00
|
|
|
$result = call_user_func_array([DateTime::class, 'WEEKOFYEAR'], $args);
|
2015-05-17 13:00:02 +00:00
|
|
|
$this->assertEquals($expectedResult, $result, null, 1E-8);
|
|
|
|
}
|
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
|
2016-05-19 10:31:40 +00:00
|
|
|
* @group fail19
|
2012-07-31 20:56:11 +00:00
|
|
|
*/
|
2015-05-17 13:00:02 +00:00
|
|
|
public function testWEEKDAY()
|
|
|
|
{
|
2016-08-14 04:32:43 +00:00
|
|
|
$this->markTestIncomplete('TODO: This test should be fixed');
|
|
|
|
|
2015-05-17 13:00:02 +00:00
|
|
|
$args = func_get_args();
|
|
|
|
$expectedResult = array_pop($args);
|
2016-08-16 15:33:57 +00:00
|
|
|
$result = call_user_func_array([DateTime::class, 'DAYOFWEEK'], $args);
|
2015-05-17 13:00:02 +00:00
|
|
|
$this->assertEquals($expectedResult, $result, null, 1E-8);
|
|
|
|
}
|
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
|
|
|
|
*/
|
2015-05-17 13:00:02 +00:00
|
|
|
public function testDAY()
|
|
|
|
{
|
|
|
|
$args = func_get_args();
|
|
|
|
$expectedResult = array_pop($args);
|
2016-08-16 15:33:57 +00:00
|
|
|
$result = call_user_func_array([DateTime::class, 'DAYOFMONTH'], $args);
|
2015-05-17 13:00:02 +00:00
|
|
|
$this->assertEquals($expectedResult, $result, null, 1E-8);
|
|
|
|
}
|
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
|
|
|
|
*/
|
2015-05-17 13:00:02 +00:00
|
|
|
public function testTIME()
|
|
|
|
{
|
|
|
|
$args = func_get_args();
|
|
|
|
$expectedResult = array_pop($args);
|
2016-08-16 15:33:57 +00:00
|
|
|
$result = call_user_func_array([DateTime::class, 'TIME'], $args);
|
2015-05-17 13:00:02 +00:00
|
|
|
$this->assertEquals($expectedResult, $result, null, 1E-8);
|
|
|
|
}
|
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-08-14 04:32:43 +00:00
|
|
|
$this->markTestIncomplete('TODO: This test should be fixed');
|
|
|
|
|
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);
|
2015-05-17 13:00:02 +00:00
|
|
|
$this->assertEquals(27020, $result, null, 1E-8);
|
|
|
|
}
|
|
|
|
|
|
|
|
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...
|
|
|
|
$this->assertTrue(is_object($result));
|
|
|
|
// ... of the correct type
|
2015-05-17 17:26:34 +00:00
|
|
|
$this->assertTrue(is_a($result, 'DateTime'));
|
2012-07-31 20:56:11 +00:00
|
|
|
// ... with the correct value
|
2015-05-17 17:26:34 +00:00
|
|
|
$this->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
|
|
|
|
*/
|
2015-05-17 13:00:02 +00:00
|
|
|
public function testTIMEVALUE()
|
|
|
|
{
|
|
|
|
$args = func_get_args();
|
|
|
|
$expectedResult = array_pop($args);
|
2016-08-16 15:33:57 +00:00
|
|
|
$result = call_user_func_array([DateTime::class, 'TIMEVALUE'], $args);
|
2015-05-17 13:00:02 +00:00
|
|
|
$this->assertEquals($expectedResult, $result, null, 1E-8);
|
|
|
|
}
|
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-08-14 04:32:43 +00:00
|
|
|
$this->markTestIncomplete('TODO: This test should be fixed');
|
|
|
|
|
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);
|
2015-05-17 13:00:02 +00:00
|
|
|
$this->assertEquals(23420, $result, null, 1E-8);
|
|
|
|
}
|
|
|
|
|
|
|
|
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...
|
|
|
|
$this->assertTrue(is_object($result));
|
|
|
|
// ... of the correct type
|
2015-05-17 17:26:34 +00:00
|
|
|
$this->assertTrue(is_a($result, 'DateTime'));
|
2012-07-31 20:56:11 +00:00
|
|
|
// ... with the correct value
|
2015-05-17 17:26:34 +00:00
|
|
|
$this->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
|
|
|
|
*/
|
2015-05-17 13:00:02 +00:00
|
|
|
public function testHOUR()
|
|
|
|
{
|
|
|
|
$args = func_get_args();
|
|
|
|
$expectedResult = array_pop($args);
|
2016-08-16 15:33:57 +00:00
|
|
|
$result = call_user_func_array([DateTime::class, 'HOUROFDAY'], $args);
|
2015-05-17 13:00:02 +00:00
|
|
|
$this->assertEquals($expectedResult, $result, null, 1E-8);
|
|
|
|
}
|
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
|
|
|
|
*/
|
2015-05-17 13:00:02 +00:00
|
|
|
public function testMINUTE()
|
|
|
|
{
|
2016-08-14 04:32:43 +00:00
|
|
|
$this->markTestIncomplete('TODO: This test should be fixed');
|
|
|
|
|
2015-05-17 13:00:02 +00:00
|
|
|
$args = func_get_args();
|
|
|
|
$expectedResult = array_pop($args);
|
2016-08-16 15:33:57 +00:00
|
|
|
$result = call_user_func_array([DateTime::class, 'MINUTEOFHOUR'], $args);
|
2015-05-17 13:00:02 +00:00
|
|
|
$this->assertEquals($expectedResult, $result, null, 1E-8);
|
|
|
|
}
|
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
|
|
|
|
*/
|
2015-05-17 13:00:02 +00:00
|
|
|
public function testSECOND()
|
|
|
|
{
|
2016-08-14 04:32:43 +00:00
|
|
|
$this->markTestIncomplete('TODO: This test should be fixed');
|
|
|
|
|
2015-05-17 13:00:02 +00:00
|
|
|
$args = func_get_args();
|
|
|
|
$expectedResult = array_pop($args);
|
2016-08-16 15:33:57 +00:00
|
|
|
$result = call_user_func_array([DateTime::class, 'SECONDOFMINUTE'], $args);
|
2015-05-17 13:00:02 +00:00
|
|
|
$this->assertEquals($expectedResult, $result, null, 1E-8);
|
|
|
|
}
|
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
|
|
|
|
*/
|
2015-05-17 13:00:02 +00:00
|
|
|
public function testNETWORKDAYS()
|
|
|
|
{
|
|
|
|
$args = func_get_args();
|
|
|
|
$expectedResult = array_pop($args);
|
2016-08-16 15:33:57 +00:00
|
|
|
$result = call_user_func_array([DateTime::class, 'NETWORKDAYS'], $args);
|
2015-05-17 13:00:02 +00:00
|
|
|
$this->assertEquals($expectedResult, $result, null, 1E-8);
|
|
|
|
}
|
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
|
|
|
|
*/
|
2015-05-17 13:00:02 +00:00
|
|
|
public function testWORKDAY()
|
|
|
|
{
|
|
|
|
$args = func_get_args();
|
|
|
|
$expectedResult = array_pop($args);
|
2016-08-16 15:33:57 +00:00
|
|
|
$result = call_user_func_array([DateTime::class, 'WORKDAY'], $args);
|
2015-05-17 13:00:02 +00:00
|
|
|
$this->assertEquals($expectedResult, $result, null, 1E-8);
|
|
|
|
}
|
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
|
|
|
|
*/
|
2015-05-17 13:00:02 +00:00
|
|
|
public function testEDATE()
|
|
|
|
{
|
|
|
|
$args = func_get_args();
|
|
|
|
$expectedResult = array_pop($args);
|
2016-08-16 15:33:57 +00:00
|
|
|
$result = call_user_func_array([DateTime::class, 'EDATE'], $args);
|
2015-05-17 13:00:02 +00:00
|
|
|
$this->assertEquals($expectedResult, $result, null, 1E-8);
|
|
|
|
}
|
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);
|
2015-05-17 13:00:02 +00:00
|
|
|
$this->assertEquals(1324857600, $result, null, 1E-8);
|
|
|
|
}
|
|
|
|
|
|
|
|
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...
|
|
|
|
$this->assertTrue(is_object($result));
|
|
|
|
// ... of the correct type
|
2015-05-17 17:26:34 +00:00
|
|
|
$this->assertTrue(is_a($result, 'DateTime'));
|
2012-07-31 20:56:11 +00:00
|
|
|
// ... with the correct value
|
2015-05-17 17:26:34 +00:00
|
|
|
$this->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
|
|
|
|
*/
|
2015-05-17 13:00:02 +00:00
|
|
|
public function testEOMONTH()
|
|
|
|
{
|
|
|
|
$args = func_get_args();
|
|
|
|
$expectedResult = array_pop($args);
|
2016-08-16 15:33:57 +00:00
|
|
|
$result = call_user_func_array([DateTime::class, 'EOMONTH'], $args);
|
2015-05-17 13:00:02 +00:00
|
|
|
$this->assertEquals($expectedResult, $result, null, 1E-8);
|
|
|
|
}
|
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);
|
2015-05-17 13:00:02 +00:00
|
|
|
$this->assertEquals(1325289600, $result, null, 1E-8);
|
|
|
|
}
|
|
|
|
|
|
|
|
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...
|
|
|
|
$this->assertTrue(is_object($result));
|
|
|
|
// ... of the correct type
|
2015-05-17 17:26:34 +00:00
|
|
|
$this->assertTrue(is_a($result, 'DateTime'));
|
2012-07-31 20:56:11 +00:00
|
|
|
// ... with the correct value
|
2015-05-17 17:26:34 +00:00
|
|
|
$this->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
|
2016-05-19 10:31:40 +00:00
|
|
|
* @group fail19
|
2012-07-31 20:56:11 +00:00
|
|
|
*/
|
2015-05-17 13:00:02 +00:00
|
|
|
public function testDATEDIF()
|
|
|
|
{
|
2016-08-14 04:32:43 +00:00
|
|
|
$this->markTestIncomplete('TODO: This test should be fixed');
|
|
|
|
|
2015-05-17 13:00:02 +00:00
|
|
|
$args = func_get_args();
|
|
|
|
$expectedResult = array_pop($args);
|
2016-08-16 15:33:57 +00:00
|
|
|
$result = call_user_func_array([DateTime::class, 'DATEDIF'], $args);
|
2015-05-17 13:00:02 +00:00
|
|
|
$this->assertEquals($expectedResult, $result, null, 1E-8);
|
|
|
|
}
|
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
|
|
|
|
*/
|
2015-05-17 13:00:02 +00:00
|
|
|
public function testDAYS360()
|
|
|
|
{
|
|
|
|
$args = func_get_args();
|
|
|
|
$expectedResult = array_pop($args);
|
2016-08-16 15:33:57 +00:00
|
|
|
$result = call_user_func_array([DateTime::class, 'DAYS360'], $args);
|
2015-05-17 13:00:02 +00:00
|
|
|
$this->assertEquals($expectedResult, $result, null, 1E-8);
|
|
|
|
}
|
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
|
2016-05-19 10:31:40 +00:00
|
|
|
* @group fail19
|
2012-07-31 20:56:11 +00:00
|
|
|
*/
|
2015-05-17 13:00:02 +00:00
|
|
|
public function testYEARFRAC()
|
|
|
|
{
|
2016-08-14 04:32:43 +00:00
|
|
|
$this->markTestIncomplete('TODO: This test should be fixed');
|
|
|
|
|
2015-05-17 13:00:02 +00:00
|
|
|
$args = func_get_args();
|
|
|
|
$expectedResult = array_pop($args);
|
2016-08-16 15:33:57 +00:00
|
|
|
$result = call_user_func_array([DateTime::class, 'YEARFRAC'], $args);
|
2015-05-17 13:00:02 +00:00
|
|
|
$this->assertEquals($expectedResult, $result, null, 1E-8);
|
|
|
|
}
|
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
|
|
|
}
|