2012-06-24 21:33:33 +00:00
|
|
|
<?php
|
|
|
|
|
2016-08-31 17:18:12 +00:00
|
|
|
namespace PhpOffice\PhpSpreadsheetTests\Shared;
|
2012-06-24 21:33:33 +00:00
|
|
|
|
2016-08-31 17:18:12 +00:00
|
|
|
use PhpOffice\PhpSpreadsheet\Shared\Date;
|
2017-05-17 22:02:17 +00:00
|
|
|
use PHPUnit_Framework_TestCase;
|
2012-06-24 21:33:33 +00:00
|
|
|
|
2017-05-17 22:02:17 +00:00
|
|
|
class DateTest extends PHPUnit_Framework_TestCase
|
2012-06-24 21:33:33 +00:00
|
|
|
{
|
2015-05-17 13:00:02 +00:00
|
|
|
public function testSetExcelCalendar()
|
|
|
|
{
|
2016-08-16 15:33:57 +00:00
|
|
|
$calendarValues = [
|
2016-08-14 04:08:43 +00:00
|
|
|
Date::CALENDAR_MAC_1904,
|
|
|
|
Date::CALENDAR_WINDOWS_1900,
|
2016-08-16 15:33:57 +00:00
|
|
|
];
|
2015-05-17 13:00:02 +00:00
|
|
|
|
|
|
|
foreach ($calendarValues as $calendarValue) {
|
2016-08-26 06:39:29 +00:00
|
|
|
$result = 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-08-26 06:39:29 +00:00
|
|
|
$result = Date::setExcelCalendar($unsupportedCalendar);
|
2015-05-17 13:00:02 +00:00
|
|
|
$this->assertFalse($result);
|
|
|
|
}
|
2012-06-24 21:33:33 +00:00
|
|
|
|
|
|
|
/**
|
2016-08-13 19:21:45 +00:00
|
|
|
* @dataProvider providerDateTimeExcelToTimestamp1900
|
2017-01-23 05:49:10 +00:00
|
|
|
*
|
|
|
|
* @param mixed $expectedResult
|
2012-06-24 21:33:33 +00:00
|
|
|
*/
|
2017-01-23 05:49:10 +00:00
|
|
|
public function testDateTimeExcelToTimestamp1900($expectedResult, ...$args)
|
2015-05-17 13:00:02 +00:00
|
|
|
{
|
2016-08-26 06:39:29 +00:00
|
|
|
Date::setExcelCalendar(Date::CALENDAR_WINDOWS_1900);
|
2015-05-17 13:00:02 +00:00
|
|
|
|
2017-01-23 05:49:10 +00:00
|
|
|
$result = Date::excelToTimestamp(...$args);
|
2015-05-17 13:00:02 +00:00
|
|
|
$this->assertEquals($expectedResult, $result);
|
|
|
|
}
|
2012-06-24 21:33:33 +00:00
|
|
|
|
2016-08-13 19:21:45 +00:00
|
|
|
public function providerDateTimeExcelToTimestamp1900()
|
2012-06-24 21:33:33 +00:00
|
|
|
{
|
2016-08-16 12:00:19 +00:00
|
|
|
return require 'data/Shared/Date/ExcelToTimestamp1900.php';
|
2015-05-17 13:00:02 +00:00
|
|
|
}
|
2012-06-24 21:33:33 +00:00
|
|
|
|
2012-07-24 12:21:31 +00:00
|
|
|
/**
|
2016-08-14 21:36:30 +00:00
|
|
|
* @dataProvider providerDateTimeTimestampToExcel1900
|
2017-01-23 05:49:10 +00:00
|
|
|
*
|
|
|
|
* @param mixed $expectedResult
|
2012-07-24 12:21:31 +00:00
|
|
|
*/
|
2017-01-23 05:49:10 +00:00
|
|
|
public function testDateTimeTimestampToExcel1900($expectedResult, ...$args)
|
2015-05-17 13:00:02 +00:00
|
|
|
{
|
2016-08-26 06:39:29 +00:00
|
|
|
Date::setExcelCalendar(Date::CALENDAR_WINDOWS_1900);
|
2015-05-17 13:00:02 +00:00
|
|
|
|
2017-01-23 05:49:10 +00:00
|
|
|
$result = Date::timestampToExcel(...$args);
|
2015-05-17 13:00:02 +00:00
|
|
|
$this->assertEquals($expectedResult, $result, null, 1E-5);
|
|
|
|
}
|
2012-07-24 12:21:31 +00:00
|
|
|
|
2016-08-14 21:36:30 +00:00
|
|
|
public function providerDateTimeTimestampToExcel1900()
|
2012-07-24 12:21:31 +00:00
|
|
|
{
|
2016-08-16 12:00:19 +00:00
|
|
|
return require 'data/Shared/Date/TimestampToExcel1900.php';
|
2016-08-14 21:36:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider providerDateTimeDateTimeToExcel
|
2017-01-23 05:49:10 +00:00
|
|
|
*
|
|
|
|
* @param mixed $expectedResult
|
2016-08-14 21:36:30 +00:00
|
|
|
*/
|
2017-01-23 05:49:10 +00:00
|
|
|
public function testDateTimeDateTimeToExcel($expectedResult, ...$args)
|
2016-08-14 21:36:30 +00:00
|
|
|
{
|
2016-08-26 06:39:29 +00:00
|
|
|
Date::setExcelCalendar(Date::CALENDAR_WINDOWS_1900);
|
2016-08-14 21:36:30 +00:00
|
|
|
|
2017-01-23 05:49:10 +00:00
|
|
|
$result = Date::dateTimeToExcel(...$args);
|
2016-08-14 21:36:30 +00:00
|
|
|
$this->assertEquals($expectedResult, $result, null, 1E-5);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function providerDateTimeDateTimeToExcel()
|
|
|
|
{
|
2016-08-16 12:00:19 +00:00
|
|
|
return require 'data/Shared/Date/DateTimeToExcel.php';
|
2015-05-17 13:00:02 +00:00
|
|
|
}
|
2012-07-24 12:21:31 +00:00
|
|
|
|
|
|
|
/**
|
2016-03-22 21:26:17 +00:00
|
|
|
* @dataProvider providerDateTimeFormattedPHPToExcel1900
|
2017-01-23 05:49:10 +00:00
|
|
|
*
|
|
|
|
* @param mixed $expectedResult
|
2012-07-24 12:21:31 +00:00
|
|
|
*/
|
2017-01-23 05:49:10 +00:00
|
|
|
public function testDateTimeFormattedPHPToExcel1900($expectedResult, ...$args)
|
2015-05-17 13:00:02 +00:00
|
|
|
{
|
2016-08-26 06:39:29 +00:00
|
|
|
Date::setExcelCalendar(Date::CALENDAR_WINDOWS_1900);
|
2015-05-17 13:00:02 +00:00
|
|
|
|
2017-01-23 05:49:10 +00:00
|
|
|
$result = 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
|
|
|
|
2016-03-22 21:26:17 +00:00
|
|
|
public function providerDateTimeFormattedPHPToExcel1900()
|
2012-07-24 12:21:31 +00:00
|
|
|
{
|
2016-08-16 12:00:19 +00:00
|
|
|
return require 'data/Shared/Date/FormattedPHPToExcel1900.php';
|
2015-05-17 13:00:02 +00:00
|
|
|
}
|
2012-07-24 12:21:31 +00:00
|
|
|
|
2012-06-24 21:33:33 +00:00
|
|
|
/**
|
2016-08-13 19:21:45 +00:00
|
|
|
* @dataProvider providerDateTimeExcelToTimestamp1904
|
2017-01-23 05:49:10 +00:00
|
|
|
*
|
|
|
|
* @param mixed $expectedResult
|
2012-06-24 21:33:33 +00:00
|
|
|
*/
|
2017-01-23 05:49:10 +00:00
|
|
|
public function testDateTimeExcelToTimestamp1904($expectedResult, ...$args)
|
2015-05-17 13:00:02 +00:00
|
|
|
{
|
2016-08-26 06:39:29 +00:00
|
|
|
Date::setExcelCalendar(Date::CALENDAR_MAC_1904);
|
2015-05-17 13:00:02 +00:00
|
|
|
|
2017-01-23 05:49:10 +00:00
|
|
|
$result = Date::excelToTimestamp(...$args);
|
2015-05-17 13:00:02 +00:00
|
|
|
$this->assertEquals($expectedResult, $result);
|
|
|
|
}
|
2012-06-24 21:33:33 +00:00
|
|
|
|
2016-08-13 19:21:45 +00:00
|
|
|
public function providerDateTimeExcelToTimestamp1904()
|
2012-06-24 21:33:33 +00:00
|
|
|
{
|
2016-08-16 12:00:19 +00:00
|
|
|
return require 'data/Shared/Date/ExcelToTimestamp1904.php';
|
2015-05-17 13:00:02 +00:00
|
|
|
}
|
2012-06-24 21:33:33 +00:00
|
|
|
|
2012-07-24 12:21:31 +00:00
|
|
|
/**
|
2016-08-14 21:36:30 +00:00
|
|
|
* @dataProvider providerDateTimeTimestampToExcel1904
|
2017-01-23 05:49:10 +00:00
|
|
|
*
|
|
|
|
* @param mixed $expectedResult
|
2012-07-24 12:21:31 +00:00
|
|
|
*/
|
2017-01-23 05:49:10 +00:00
|
|
|
public function testDateTimeTimestampToExcel1904($expectedResult, ...$args)
|
2015-05-17 13:00:02 +00:00
|
|
|
{
|
2016-08-26 06:39:29 +00:00
|
|
|
Date::setExcelCalendar(Date::CALENDAR_MAC_1904);
|
2015-05-17 13:00:02 +00:00
|
|
|
|
2017-01-23 05:49:10 +00:00
|
|
|
$result = Date::timestampToExcel(...$args);
|
2015-05-17 13:00:02 +00:00
|
|
|
$this->assertEquals($expectedResult, $result, null, 1E-5);
|
|
|
|
}
|
2012-07-24 12:21:31 +00:00
|
|
|
|
2016-08-14 21:36:30 +00:00
|
|
|
public function providerDateTimeTimestampToExcel1904()
|
2012-07-24 12:21:31 +00:00
|
|
|
{
|
2016-08-16 12:00:19 +00:00
|
|
|
return require 'data/Shared/Date/TimestampToExcel1904.php';
|
2015-05-17 13:00:02 +00:00
|
|
|
}
|
2012-07-24 12:21:31 +00:00
|
|
|
|
2012-06-24 21:33:33 +00:00
|
|
|
/**
|
|
|
|
* @dataProvider providerIsDateTimeFormatCode
|
2017-01-23 05:49:10 +00:00
|
|
|
*
|
|
|
|
* @param mixed $expectedResult
|
2012-06-24 21:33:33 +00:00
|
|
|
*/
|
2017-01-23 05:49:10 +00:00
|
|
|
public function testIsDateTimeFormatCode($expectedResult, ...$args)
|
2015-05-17 13:00:02 +00:00
|
|
|
{
|
2017-01-23 05:49:10 +00:00
|
|
|
$result = 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()
|
|
|
|
{
|
2016-08-16 12:00:19 +00:00
|
|
|
return require 'data/Shared/Date/FormatCodes.php';
|
2015-05-17 13:00:02 +00:00
|
|
|
}
|
2012-06-24 21:33:33 +00:00
|
|
|
|
2012-11-02 23:07:01 +00:00
|
|
|
/**
|
2016-08-13 19:21:45 +00:00
|
|
|
* @dataProvider providerDateTimeExcelToTimestamp1900Timezone
|
2017-01-23 05:49:10 +00:00
|
|
|
*
|
|
|
|
* @param mixed $expectedResult
|
2012-11-02 23:07:01 +00:00
|
|
|
*/
|
2017-01-23 05:49:10 +00:00
|
|
|
public function testDateTimeExcelToTimestamp1900Timezone($expectedResult, ...$args)
|
2015-05-17 13:00:02 +00:00
|
|
|
{
|
2016-08-26 06:39:29 +00:00
|
|
|
Date::setExcelCalendar(Date::CALENDAR_WINDOWS_1900);
|
2015-05-17 13:00:02 +00:00
|
|
|
|
2017-01-23 05:49:10 +00:00
|
|
|
$result = Date::excelToTimestamp(...$args);
|
2015-05-17 13:00:02 +00:00
|
|
|
$this->assertEquals($expectedResult, $result);
|
|
|
|
}
|
2012-11-02 23:07:01 +00:00
|
|
|
|
2016-08-13 19:21:45 +00:00
|
|
|
public function providerDateTimeExcelToTimestamp1900Timezone()
|
2012-11-02 23:07:01 +00:00
|
|
|
{
|
2016-08-16 12:00:19 +00:00
|
|
|
return require 'data/Shared/Date/ExcelToTimestamp1900Timezone.php';
|
2015-05-17 13:00:02 +00:00
|
|
|
}
|
2012-06-24 21:33:33 +00:00
|
|
|
}
|