Unit Tests for Date helper functions

This commit is contained in:
Mark Baker 2012-07-24 13:21:31 +01:00
parent dbe12c73a2
commit b7dfeb9bb7
6 changed files with 106 additions and 3 deletions

View File

@ -46,6 +46,9 @@ class DateTest extends PHPUnit_Framework_TestCase
$args = func_get_args(); $args = func_get_args();
$expectedResult = array_pop($args); $expectedResult = array_pop($args);
if ($args[0] < 1) {
$expectedResult += gmmktime(0,0,0);
}
$result = call_user_func_array(array('PHPExcel_Shared_Date','ExcelToPHP'),$args); $result = call_user_func_array(array('PHPExcel_Shared_Date','ExcelToPHP'),$args);
$this->assertEquals($expectedResult, $result); $this->assertEquals($expectedResult, $result);
} }
@ -55,6 +58,48 @@ class DateTest extends PHPUnit_Framework_TestCase
return new testDataFileIterator('rawTestData/Shared/DateTimeExcelToPHP1900.data'); return new testDataFileIterator('rawTestData/Shared/DateTimeExcelToPHP1900.data');
} }
/**
* @dataProvider providerDateTimePHPToExcel1900
*/
public function testDateTimePHPToExcel1900()
{
$result = call_user_func(
array('PHPExcel_Shared_Date','setExcelCalendar'),
PHPExcel_Shared_Date::CALENDAR_WINDOWS_1900
);
$args = func_get_args();
$expectedResult = array_pop($args);
$result = call_user_func_array(array('PHPExcel_Shared_Date','PHPToExcel'),$args);
$this->assertEquals($expectedResult, $result, NULL, 1E-5);
}
public function providerDateTimePHPToExcel1900()
{
return new testDataFileIterator('rawTestData/Shared/DateTimePHPToExcel1900.data');
}
/**
* @dataProvider providerDateTimeFormattedPHPToExcel1900
*/
public function testDateTimeFormattedPHPToExcel1900()
{
$result = call_user_func(
array('PHPExcel_Shared_Date','setExcelCalendar'),
PHPExcel_Shared_Date::CALENDAR_WINDOWS_1900
);
$args = func_get_args();
$expectedResult = array_pop($args);
$result = call_user_func_array(array('PHPExcel_Shared_Date','FormattedPHPToExcel'),$args);
$this->assertEquals($expectedResult, $result, NULL, 1E-5);
}
public function providerDateTimeFormattedPHPToExcel1900()
{
return new testDataFileIterator('rawTestData/Shared/DateTimeFormattedPHPToExcel1900.data');
}
/** /**
* @dataProvider providerDateTimeExcelToPHP1904 * @dataProvider providerDateTimeExcelToPHP1904
*/ */
@ -67,6 +112,9 @@ class DateTest extends PHPUnit_Framework_TestCase
$args = func_get_args(); $args = func_get_args();
$expectedResult = array_pop($args); $expectedResult = array_pop($args);
if ($args[0] < 1) {
$expectedResult += gmmktime(0,0,0);
}
$result = call_user_func_array(array('PHPExcel_Shared_Date','ExcelToPHP'),$args); $result = call_user_func_array(array('PHPExcel_Shared_Date','ExcelToPHP'),$args);
$this->assertEquals($expectedResult, $result); $this->assertEquals($expectedResult, $result);
} }
@ -76,6 +124,27 @@ class DateTest extends PHPUnit_Framework_TestCase
return new testDataFileIterator('rawTestData/Shared/DateTimeExcelToPHP1904.data'); return new testDataFileIterator('rawTestData/Shared/DateTimeExcelToPHP1904.data');
} }
/**
* @dataProvider providerDateTimePHPToExcel1904
*/
public function testDateTimePHPToExcel1904()
{
$result = call_user_func(
array('PHPExcel_Shared_Date','setExcelCalendar'),
PHPExcel_Shared_Date::CALENDAR_MAC_1904
);
$args = func_get_args();
$expectedResult = array_pop($args);
$result = call_user_func_array(array('PHPExcel_Shared_Date','PHPToExcel'),$args);
$this->assertEquals($expectedResult, $result, NULL, 1E-5);
}
public function providerDateTimePHPToExcel1904()
{
return new testDataFileIterator('rawTestData/Shared/DateTimePHPToExcel1904.data');
}
/** /**
* @dataProvider providerIsDateTimeFormatCode * @dataProvider providerIsDateTimeFormatCode
*/ */

View File

@ -10,6 +10,6 @@
50424, 2147472000 // PHP 32-bit Latest Date 19-Jan-2038 50424, 2147472000 // PHP 32-bit Latest Date 19-Jan-2038
1234.56789, -2102494934 // 18-May-1903 13:37:46 1234.56789, -2102494934 // 18-May-1903 13:37:46
12345.6789, -1142494943 // 18-Oct-1933 16:17:37 12345.6789, -1142494943 // 18-Oct-1933 16:17:37
0.5, 1340539200 // 12:00:00 0.5, 43200 // 12:00:00
0.75, 1340560800 // 18:00.00 0.75, 64800 // 18:00.00
0.12345, 1340506666 // 02:57:46 0.12345, 10666 // 02:57:46

View File

@ -5,3 +5,6 @@
25569, 126316800 25569, 126316800
30292, 534384000 30292, 534384000
39611, 1339545600 39611, 1339545600
0.25, 21600 // 06:00:00
0.3333333333333333333, 28800 // 08:00.00
0.54321, 46933 // 02:57:46

View File

@ -0,0 +1,12 @@
#Year Month Day Hours Minutes Seconds Result Comments
1901, 12, 14, 714 // PHP 32-bit Earliest Date 14-Dec-1901
1903, 12, 31, 1461 // 31-Dec-1903
1904, 1, 1, 1462 // Excel 1904 Calendar Base Date 01-Jan-1904
1904, 1, 2, 1463 // 02-Jan-1904
1960, 12, 19, 22269 // 19-Dec-1960
1970, 1, 1, 25569 // PHP Base Date 01-Jan-1970
1982, 12, 7, 30292 // 07-Dec-1982
2008, 6, 12, 39611 // 12-Jun-2008
2038, 1, 19, 50424 // PHP 32-bit Latest Date 19-Jan-2038
1903, 5, 18, 13, 37, 46, 1234.56789 // 18-May-1903 13:37:46
1933, 10, 18, 16, 17, 37, 12345.6789 // 18-Oct-1933 16:17:37

View File

@ -0,0 +1,12 @@
#Excel DateTimeStamp Result Comments
-2147472000, 714 // PHP 32-bit Earliest Date 14-Dec-1901
-2082931200, 1461 // 31-Dec-1903
-2082844800, 1462 // Excel 1904 Calendar Base Date 01-Jan-1904
-2082758400, 1463 // 02-Jan-1904
-285120000, 22269 // 19-Dec-1960
0, 25569 // PHP Base Date 01-Jan-1970
408067200, 30292 // 07-Dec-1982
1213228800, 39611 // 12-Jun-2008
2147472000, 50424 // PHP 32-bit Latest Date 19-Jan-2038
-2102494934, 1234.56789 // 18-May-1903 13:37:46
-1142494943, 12345.6789 // 18-Oct-1933 16:17:37

View File

@ -0,0 +1,7 @@
#Excel DateTimeStamp Result
-1956528000, 1462
-1956441600, 1463
-158803200, 22269
126316800, 25569
534384000, 30292
1339545600, 39611