| 
									
										
										
										
											2019-07-21 18:55:41 +00:00
										 |  |  | <?php | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\DateTime; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-25 17:15:53 +00:00
										 |  |  | use DateTimeInterface; | 
					
						
							| 
									
										
										
										
											2019-07-21 18:55:41 +00:00
										 |  |  | use PhpOffice\PhpSpreadsheet\Calculation\DateTime; | 
					
						
							|  |  |  | use PhpOffice\PhpSpreadsheet\Calculation\Functions; | 
					
						
							|  |  |  | use PhpOffice\PhpSpreadsheet\Shared\Date; | 
					
						
							|  |  |  | use PHPUnit\Framework\TestCase; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class DateValueTest extends TestCase | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2020-04-27 10:28:36 +00:00
										 |  |  |     protected function setUp(): void | 
					
						
							| 
									
										
										
										
											2019-07-21 18:55:41 +00:00
										 |  |  |     { | 
					
						
							|  |  |  |         Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL); | 
					
						
							|  |  |  |         Functions::setReturnDateType(Functions::RETURNDATE_EXCEL); | 
					
						
							|  |  |  |         Date::setExcelCalendar(Date::CALENDAR_WINDOWS_1900); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * @dataProvider providerDATEVALUE | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @param mixed $expectedResult | 
					
						
							| 
									
										
										
										
											2019-07-22 22:50:30 +00:00
										 |  |  |      * @param $dateValue | 
					
						
							| 
									
										
										
										
											2019-07-21 18:55:41 +00:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2019-07-22 22:50:30 +00:00
										 |  |  |     public function testDATEVALUE($expectedResult, $dateValue) | 
					
						
							| 
									
										
										
										
											2019-07-21 18:55:41 +00:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2019-07-22 22:50:30 +00:00
										 |  |  |         $result = DateTime::DATEVALUE($dateValue); | 
					
						
							| 
									
										
										
										
											2020-04-27 10:28:36 +00:00
										 |  |  |         $this->assertEqualsWithDelta($expectedResult, $result, 1E-8); | 
					
						
							| 
									
										
										
										
											2019-07-21 18:55:41 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     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'); | 
					
						
							| 
									
										
										
										
											2020-04-27 10:28:36 +00:00
										 |  |  |         $this->assertEquals(1327968000, $result); | 
					
						
							|  |  |  |         $this->assertEqualsWithDelta(1327968000, $result, 1E-8); | 
					
						
							| 
									
										
										
										
											2019-07-21 18:55:41 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     public function testDATEVALUEtoDateTimeObject() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         Functions::setReturnDateType(Functions::RETURNDATE_PHP_DATETIME_OBJECT); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $result = DateTime::DATEVALUE('2012-1-31'); | 
					
						
							|  |  |  |         //    Must return an object...
 | 
					
						
							| 
									
										
										
										
											2019-07-27 12:28:16 +00:00
										 |  |  |         $this->assertIsObject($result); | 
					
						
							| 
									
										
										
										
											2019-07-21 18:55:41 +00:00
										 |  |  |         //    ... of the correct type
 | 
					
						
							| 
									
										
										
										
											2019-07-25 17:15:53 +00:00
										 |  |  |         $this->assertTrue(is_a($result, DateTimeInterface::class)); | 
					
						
							| 
									
										
										
										
											2019-07-21 18:55:41 +00:00
										 |  |  |         //    ... with the correct value
 | 
					
						
							|  |  |  |         $this->assertEquals($result->format('d-M-Y'), '31-Jan-2012'); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } |