PhpSpreadsheet/tests/PhpSpreadsheetTests/Shared/DateTest.php

172 lines
4.8 KiB
PHP
Raw Normal View History

2012-06-24 21:33:33 +00:00
<?php
namespace PhpOffice\PhpSpreadsheetTests\Shared;
2012-06-24 21:33:33 +00:00
use PhpOffice\PhpSpreadsheet\Shared\Date;
use PHPUnit\Framework\TestCase;
2012-06-24 21:33:33 +00:00
class DateTest extends TestCase
2012-06-24 21:33:33 +00:00
{
2015-05-17 13:00:02 +00:00
public function testSetExcelCalendar()
{
$calendarValues = [
Date::CALENDAR_MAC_1904,
Date::CALENDAR_WINDOWS_1900,
];
2015-05-17 13:00:02 +00:00
foreach ($calendarValues as $calendarValue) {
$result = Date::setExcelCalendar($calendarValue);
self::assertTrue($result);
2015-05-17 13:00:02 +00:00
}
}
2012-06-24 21:33:33 +00:00
public function testSetExcelCalendarWithInvalidValue()
2015-05-17 13:00:02 +00:00
{
$unsupportedCalendar = '2012';
$result = Date::setExcelCalendar($unsupportedCalendar);
self::assertFalse($result);
2015-05-17 13:00:02 +00:00
}
2012-06-24 21:33:33 +00:00
/**
2016-08-13 19:21:45 +00:00
* @dataProvider providerDateTimeExcelToTimestamp1900
*
* @param mixed $expectedResult
2012-06-24 21:33:33 +00:00
*/
public function testDateTimeExcelToTimestamp1900($expectedResult, ...$args)
2015-05-17 13:00:02 +00:00
{
Date::setExcelCalendar(Date::CALENDAR_WINDOWS_1900);
2015-05-17 13:00:02 +00:00
$result = Date::excelToTimestamp(...$args);
self::assertEquals($expectedResult, $result);
2015-05-17 13:00:02 +00:00
}
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
{
return require 'tests/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
/**
* @dataProvider providerDateTimeTimestampToExcel1900
*
* @param mixed $expectedResult
2012-07-24 12:21:31 +00:00
*/
public function testDateTimeTimestampToExcel1900($expectedResult, ...$args)
2015-05-17 13:00:02 +00:00
{
Date::setExcelCalendar(Date::CALENDAR_WINDOWS_1900);
2015-05-17 13:00:02 +00:00
$result = Date::timestampToExcel(...$args);
2020-04-27 10:28:36 +00:00
self::assertEqualsWithDelta($expectedResult, $result, 1E-5);
2015-05-17 13:00:02 +00:00
}
2012-07-24 12:21:31 +00:00
public function providerDateTimeTimestampToExcel1900()
2012-07-24 12:21:31 +00:00
{
return require 'tests/data/Shared/Date/TimestampToExcel1900.php';
}
/**
* @dataProvider providerDateTimeDateTimeToExcel
*
* @param mixed $expectedResult
*/
public function testDateTimeDateTimeToExcel($expectedResult, ...$args)
{
Date::setExcelCalendar(Date::CALENDAR_WINDOWS_1900);
$result = Date::dateTimeToExcel(...$args);
2020-04-27 10:28:36 +00:00
self::assertEqualsWithDelta($expectedResult, $result, 1E-5);
}
public function providerDateTimeDateTimeToExcel()
{
return require 'tests/data/Shared/Date/DateTimeToExcel.php';
2015-05-17 13:00:02 +00:00
}
2012-07-24 12:21:31 +00:00
/**
* @dataProvider providerDateTimeFormattedPHPToExcel1900
*
* @param mixed $expectedResult
2012-07-24 12:21:31 +00:00
*/
public function testDateTimeFormattedPHPToExcel1900($expectedResult, ...$args)
2015-05-17 13:00:02 +00:00
{
Date::setExcelCalendar(Date::CALENDAR_WINDOWS_1900);
2015-05-17 13:00:02 +00:00
$result = Date::formattedPHPToExcel(...$args);
2020-04-27 10:28:36 +00:00
self::assertEqualsWithDelta($expectedResult, $result, 1E-5);
2015-05-17 13:00:02 +00:00
}
2012-07-24 12:21:31 +00:00
public function providerDateTimeFormattedPHPToExcel1900()
2012-07-24 12:21:31 +00:00
{
return require 'tests/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
*
* @param mixed $expectedResult
2012-06-24 21:33:33 +00:00
*/
public function testDateTimeExcelToTimestamp1904($expectedResult, ...$args)
2015-05-17 13:00:02 +00:00
{
Date::setExcelCalendar(Date::CALENDAR_MAC_1904);
2015-05-17 13:00:02 +00:00
$result = Date::excelToTimestamp(...$args);
self::assertEquals($expectedResult, $result);
2015-05-17 13:00:02 +00:00
}
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
{
return require 'tests/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
/**
* @dataProvider providerDateTimeTimestampToExcel1904
*
* @param mixed $expectedResult
2012-07-24 12:21:31 +00:00
*/
public function testDateTimeTimestampToExcel1904($expectedResult, ...$args)
2015-05-17 13:00:02 +00:00
{
Date::setExcelCalendar(Date::CALENDAR_MAC_1904);
2015-05-17 13:00:02 +00:00
$result = Date::timestampToExcel(...$args);
2020-04-27 10:28:36 +00:00
self::assertEqualsWithDelta($expectedResult, $result, 1E-5);
2015-05-17 13:00:02 +00:00
}
2012-07-24 12:21:31 +00:00
public function providerDateTimeTimestampToExcel1904()
2012-07-24 12:21:31 +00:00
{
return require 'tests/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
*
* @param mixed $expectedResult
2012-06-24 21:33:33 +00:00
*/
public function testIsDateTimeFormatCode($expectedResult, ...$args)
2015-05-17 13:00:02 +00:00
{
$result = Date::isDateTimeFormatCode(...$args);
self::assertEquals($expectedResult, $result);
2015-05-17 13:00:02 +00:00
}
2012-06-24 21:33:33 +00:00
public function providerIsDateTimeFormatCode()
{
return require 'tests/data/Shared/Date/FormatCodes.php';
2015-05-17 13:00:02 +00:00
}
2012-06-24 21:33:33 +00:00
/**
2016-08-13 19:21:45 +00:00
* @dataProvider providerDateTimeExcelToTimestamp1900Timezone
*
* @param mixed $expectedResult
*/
public function testDateTimeExcelToTimestamp1900Timezone($expectedResult, ...$args)
2015-05-17 13:00:02 +00:00
{
Date::setExcelCalendar(Date::CALENDAR_WINDOWS_1900);
2015-05-17 13:00:02 +00:00
$result = Date::excelToTimestamp(...$args);
self::assertEquals($expectedResult, $result);
2015-05-17 13:00:02 +00:00
}
2016-08-13 19:21:45 +00:00
public function providerDateTimeExcelToTimestamp1900Timezone()
{
return require 'tests/data/Shared/Date/ExcelToTimestamp1900Timezone.php';
2015-05-17 13:00:02 +00:00
}
2012-06-24 21:33:33 +00:00
}