| 
									
										
										
										
											2012-06-24 21:33:33 +00:00
										 |  |  | <?php | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | require_once 'testDataFileIterator.php'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class DateTest extends PHPUnit_Framework_TestCase | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2015-05-17 13:00:02 +00:00
										 |  |  |     public function testSetExcelCalendar() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $calendarValues = array( | 
					
						
							| 
									
										
										
										
											2016-03-22 14:19:00 +00:00
										 |  |  |             \PHPExcel\Shared\Date::CALENDAR_MAC_1904, | 
					
						
							|  |  |  |             \PHPExcel\Shared\Date::CALENDAR_WINDOWS_1900, | 
					
						
							| 
									
										
										
										
											2015-05-17 13:00:02 +00:00
										 |  |  |         ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         foreach ($calendarValues as $calendarValue) { | 
					
						
							| 
									
										
										
										
											2016-03-22 14:19:00 +00:00
										 |  |  |             $result = call_user_func(array('\PHPExcel\Shared\Date','setExcelCalendar'), $calendarValue); | 
					
						
							| 
									
										
										
										
											2015-05-17 13:00:02 +00:00
										 |  |  |             $this->assertTrue($result); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2012-06-24 21:33:33 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     public function testSetExcelCalendarWithInvalidValue() | 
					
						
							| 
									
										
										
										
											2015-05-17 13:00:02 +00:00
										 |  |  |     { | 
					
						
							|  |  |  |         $unsupportedCalendar = '2012'; | 
					
						
							| 
									
										
										
										
											2016-03-22 14:19:00 +00:00
										 |  |  |         $result = call_user_func(array('\PHPExcel\Shared\Date','setExcelCalendar'), $unsupportedCalendar); | 
					
						
							| 
									
										
										
										
											2015-05-17 13:00:02 +00:00
										 |  |  |         $this->assertFalse($result); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2012-06-24 21:33:33 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * @dataProvider providerDateTimeExcelToPHP1900 | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2015-05-17 13:00:02 +00:00
										 |  |  |     public function testDateTimeExcelToPHP1900() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $result = call_user_func( | 
					
						
							| 
									
										
										
										
											2016-03-22 14:19:00 +00:00
										 |  |  |             array('\PHPExcel\Shared\Date','setExcelCalendar'), | 
					
						
							|  |  |  |             \PHPExcel\Shared\Date::CALENDAR_WINDOWS_1900 | 
					
						
							| 
									
										
										
										
											2015-05-17 13:00:02 +00:00
										 |  |  |         ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $args = func_get_args(); | 
					
						
							|  |  |  |         $expectedResult = array_pop($args); | 
					
						
							|  |  |  |         if ($args[0] < 1) { | 
					
						
							| 
									
										
										
										
											2015-05-17 17:26:34 +00:00
										 |  |  |             $expectedResult += gmmktime(0, 0, 0); | 
					
						
							| 
									
										
										
										
											2015-05-17 13:00:02 +00:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2016-03-22 14:19:00 +00:00
										 |  |  |         $result = call_user_func_array(array('\PHPExcel\Shared\Date', 'ExcelToPHP'), $args); | 
					
						
							| 
									
										
										
										
											2015-05-17 13:00:02 +00:00
										 |  |  |         $this->assertEquals($expectedResult, $result); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2012-06-24 21:33:33 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     public function providerDateTimeExcelToPHP1900() | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2015-05-17 13:00:02 +00:00
										 |  |  |         return new testDataFileIterator('rawTestData/Shared/DateTimeExcelToPHP1900.data'); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2012-06-24 21:33:33 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-07-24 12:21:31 +00:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * @dataProvider providerDateTimePHPToExcel1900 | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2015-05-17 13:00:02 +00:00
										 |  |  |     public function testDateTimePHPToExcel1900() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $result = call_user_func( | 
					
						
							| 
									
										
										
										
											2016-03-22 14:19:00 +00:00
										 |  |  |             array('\PHPExcel\Shared\Date','setExcelCalendar'), | 
					
						
							|  |  |  |             \PHPExcel\Shared\Date::CALENDAR_WINDOWS_1900 | 
					
						
							| 
									
										
										
										
											2015-05-17 13:00:02 +00:00
										 |  |  |         ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $args = func_get_args(); | 
					
						
							|  |  |  |         $expectedResult = array_pop($args); | 
					
						
							| 
									
										
										
										
											2016-03-22 14:19:00 +00:00
										 |  |  |         $result = call_user_func_array(array('\PHPExcel\Shared\Date','PHPToExcel'), $args); | 
					
						
							| 
									
										
										
										
											2015-05-17 13:00:02 +00:00
										 |  |  |         $this->assertEquals($expectedResult, $result, null, 1E-5); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2012-07-24 12:21:31 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     public function providerDateTimePHPToExcel1900() | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2015-05-17 13:00:02 +00:00
										 |  |  |         return new testDataFileIterator('rawTestData/Shared/DateTimePHPToExcel1900.data'); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2012-07-24 12:21:31 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * @dataProvider providerDateTimeFormattedPHPToExcel1900 | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2015-05-17 13:00:02 +00:00
										 |  |  |     public function testDateTimeFormattedPHPToExcel1900() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $result = call_user_func( | 
					
						
							| 
									
										
										
										
											2016-03-22 14:19:00 +00:00
										 |  |  |             array('\PHPExcel\Shared\Date','setExcelCalendar'), | 
					
						
							|  |  |  |             \PHPExcel\Shared\Date::CALENDAR_WINDOWS_1900 | 
					
						
							| 
									
										
										
										
											2015-05-17 13:00:02 +00:00
										 |  |  |         ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $args = func_get_args(); | 
					
						
							|  |  |  |         $expectedResult = array_pop($args); | 
					
						
							| 
									
										
										
										
											2016-03-22 14:19:00 +00:00
										 |  |  |         $result = call_user_func_array(array('\PHPExcel\Shared\Date','FormattedPHPToExcel'), $args); | 
					
						
							| 
									
										
										
										
											2015-05-17 13:00:02 +00:00
										 |  |  |         $this->assertEquals($expectedResult, $result, null, 1E-5); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2012-07-24 12:21:31 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     public function providerDateTimeFormattedPHPToExcel1900() | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2015-05-17 13:00:02 +00:00
										 |  |  |         return new testDataFileIterator('rawTestData/Shared/DateTimeFormattedPHPToExcel1900.data'); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2012-07-24 12:21:31 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-06-24 21:33:33 +00:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * @dataProvider providerDateTimeExcelToPHP1904 | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2015-05-17 13:00:02 +00:00
										 |  |  |     public function testDateTimeExcelToPHP1904() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $result = call_user_func( | 
					
						
							| 
									
										
										
										
											2016-03-22 14:19:00 +00:00
										 |  |  |             array('\PHPExcel\Shared\Date','setExcelCalendar'), | 
					
						
							|  |  |  |             \PHPExcel\Shared\Date::CALENDAR_MAC_1904 | 
					
						
							| 
									
										
										
										
											2015-05-17 13:00:02 +00:00
										 |  |  |         ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $args = func_get_args(); | 
					
						
							|  |  |  |         $expectedResult = array_pop($args); | 
					
						
							|  |  |  |         if ($args[0] < 1) { | 
					
						
							| 
									
										
										
										
											2015-05-17 17:26:34 +00:00
										 |  |  |             $expectedResult += gmmktime(0, 0, 0); | 
					
						
							| 
									
										
										
										
											2015-05-17 13:00:02 +00:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2016-03-22 14:19:00 +00:00
										 |  |  |         $result = call_user_func_array(array('\PHPExcel\Shared\Date','ExcelToPHP'), $args); | 
					
						
							| 
									
										
										
										
											2015-05-17 13:00:02 +00:00
										 |  |  |         $this->assertEquals($expectedResult, $result); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2012-06-24 21:33:33 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     public function providerDateTimeExcelToPHP1904() | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2015-05-17 13:00:02 +00:00
										 |  |  |         return new testDataFileIterator('rawTestData/Shared/DateTimeExcelToPHP1904.data'); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2012-06-24 21:33:33 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-07-24 12:21:31 +00:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * @dataProvider providerDateTimePHPToExcel1904 | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2015-05-17 13:00:02 +00:00
										 |  |  |     public function testDateTimePHPToExcel1904() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $result = call_user_func( | 
					
						
							| 
									
										
										
										
											2016-03-22 14:19:00 +00:00
										 |  |  |             array('\PHPExcel\Shared\Date','setExcelCalendar'), | 
					
						
							|  |  |  |             \PHPExcel\Shared\Date::CALENDAR_MAC_1904 | 
					
						
							| 
									
										
										
										
											2015-05-17 13:00:02 +00:00
										 |  |  |         ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $args = func_get_args(); | 
					
						
							|  |  |  |         $expectedResult = array_pop($args); | 
					
						
							| 
									
										
										
										
											2016-03-22 14:19:00 +00:00
										 |  |  |         $result = call_user_func_array(array('\PHPExcel\Shared\Date','PHPToExcel'), $args); | 
					
						
							| 
									
										
										
										
											2015-05-17 13:00:02 +00:00
										 |  |  |         $this->assertEquals($expectedResult, $result, null, 1E-5); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2012-07-24 12:21:31 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     public function providerDateTimePHPToExcel1904() | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2015-05-17 13:00:02 +00:00
										 |  |  |         return new testDataFileIterator('rawTestData/Shared/DateTimePHPToExcel1904.data'); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2012-07-24 12:21:31 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-06-24 21:33:33 +00:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * @dataProvider providerIsDateTimeFormatCode | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2015-05-17 13:00:02 +00:00
										 |  |  |     public function testIsDateTimeFormatCode() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $args = func_get_args(); | 
					
						
							|  |  |  |         $expectedResult = array_pop($args); | 
					
						
							| 
									
										
										
										
											2016-03-22 14:19:00 +00:00
										 |  |  |         $result = call_user_func_array(array('\PHPExcel\Shared\Date','isDateTimeFormatCode'), $args); | 
					
						
							| 
									
										
										
										
											2015-05-17 13:00:02 +00:00
										 |  |  |         $this->assertEquals($expectedResult, $result); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2012-06-24 21:33:33 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     public function providerIsDateTimeFormatCode() | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2015-05-17 13:00:02 +00:00
										 |  |  |         return new testDataFileIterator('rawTestData/Shared/DateTimeFormatCodes.data'); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2012-06-24 21:33:33 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-11-02 23:07:01 +00:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * @dataProvider providerDateTimeExcelToPHP1900Timezone | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2015-05-17 13:00:02 +00:00
										 |  |  |     public function testDateTimeExcelToPHP1900Timezone() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $result = call_user_func( | 
					
						
							| 
									
										
										
										
											2016-03-22 14:19:00 +00:00
										 |  |  |             array('\PHPExcel\Shared\Date','setExcelCalendar'), | 
					
						
							|  |  |  |             \PHPExcel\Shared\Date::CALENDAR_WINDOWS_1900 | 
					
						
							| 
									
										
										
										
											2015-05-17 13:00:02 +00:00
										 |  |  |         ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $args = func_get_args(); | 
					
						
							|  |  |  |         $expectedResult = array_pop($args); | 
					
						
							|  |  |  |         if ($args[0] < 1) { | 
					
						
							| 
									
										
										
										
											2015-05-17 17:26:34 +00:00
										 |  |  |             $expectedResult += gmmktime(0, 0, 0); | 
					
						
							| 
									
										
										
										
											2015-05-17 13:00:02 +00:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2016-03-22 14:19:00 +00:00
										 |  |  |         $result = call_user_func_array(array('\PHPExcel\Shared\Date','ExcelToPHP'), $args); | 
					
						
							| 
									
										
										
										
											2015-05-17 13:00:02 +00:00
										 |  |  |         $this->assertEquals($expectedResult, $result); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2012-11-02 23:07:01 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     public function providerDateTimeExcelToPHP1900Timezone() | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2015-05-17 13:00:02 +00:00
										 |  |  |         return new testDataFileIterator('rawTestData/Shared/DateTimeExcelToPHP1900Timezone.data'); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2012-06-24 21:33:33 +00:00
										 |  |  | } |