spout/tests/Spout/Reader/XLSX/Helper/DateFormatHelperTest.php
Adrien Loison bfc76c3100 Option to return formatted dates instead of PHP objects
When reading spreadsheets, Spout should be able to return formatted dates, as shown when opened with Excel for instance.
It currently only returns DateTime/DateInterval objects, making it impossible to read + write, as the Writer does not accept objects.
2016-05-20 16:03:22 -07:00

48 lines
1.3 KiB
PHP

<?php
namespace Box\Spout\Reader\XLSX\Helper;
/**
* Class DateFormatHelperTest
*
* @package Box\Spout\Reader\XLSX\Helper
*/
class DateFormatHelperTest extends \PHPUnit_Framework_TestCase
{
/**
* @return array
*/
public function dataProviderForTestToPHPDateFormat()
{
return [
// Excel date format, expected PHP date format
['m/d/yy hh:mm', 'n/j/y H:i'],
['mmm-yy', 'M-y'],
['d-mmm-yy', 'j-M-y'],
['m/dd/yyyy', 'n/d/Y'],
['e mmmmm dddd', 'Y M l'],
['MMMM DDD', 'F D'],
['hh:mm:ss.s', 'H:i:s'],
['h:mm:ss AM/PM', 'g:i:s A'],
['hh:mm AM/PM', 'h:i A'],
['[$-409]hh:mm AM/PM', 'h:i A'],
['[$USD-F480]hh:mm AM/PM', 'h:i A'],
['"Day " d', '\\D\\a\\y\\ j'],
['yy "Year" m "Month"', 'y \\Y\\e\\a\\r n \\M\\o\\n\\t\\h'],
];
}
/**
* @dataProvider dataProviderForTestToPHPDateFormat
*
* @param string $excelDateFormat
* @param string $expectedPHPDateFormat
* @return void
*/
public function testToPHPDateFormat($excelDateFormat, $expectedPHPDateFormat)
{
$phpDateFormat = DateFormatHelper::toPHPDateFormat($excelDateFormat);
$this->assertEquals($expectedPHPDateFormat, $phpDateFormat);
}
}