mirror of
https://github.com/PHPOffice/PhpSpreadsheet.git
synced 2026-09-16 13:06:31 +00:00
Merge branch 'master' into NumberFormat-Wizard-Duration
This commit is contained in:
@@ -73,6 +73,12 @@ class Date extends DateTimeWizard
|
||||
public const SEPARATOR_SPACE_NONBREAKING = "\u{a0}";
|
||||
public const SEPARATOR_SPACE = ' ';
|
||||
|
||||
protected const DATE_DEFAULT = [
|
||||
self::YEAR_FULL,
|
||||
self::MONTH_NUMBER_LONG,
|
||||
self::DAY_NUMBER_LONG,
|
||||
];
|
||||
|
||||
/**
|
||||
* @var string[]
|
||||
*/
|
||||
@@ -89,8 +95,11 @@ class Date extends DateTimeWizard
|
||||
* if you wish to use different separators, then they should be passed as an array.
|
||||
* If you want to use only a single format block, then pass a null as the separator argument
|
||||
*/
|
||||
public function __construct($separators, string ...$formatBlocks)
|
||||
public function __construct($separators = self::SEPARATOR_DASH, string ...$formatBlocks)
|
||||
{
|
||||
$separators ??= self::SEPARATOR_DASH;
|
||||
$formatBlocks = (count($formatBlocks) === 0) ? self::DATE_DEFAULT : $formatBlocks;
|
||||
|
||||
$this->separators = $this->padSeparatorArray(
|
||||
is_array($separators) ? $separators : [$separators],
|
||||
count($formatBlocks) - 1
|
||||
|
||||
@@ -50,6 +50,12 @@ class Time extends DateTimeWizard
|
||||
public const SEPARATOR_SPACE_NONBREAKING = "\u{a0}";
|
||||
public const SEPARATOR_SPACE = ' ';
|
||||
|
||||
protected const TIME_DEFAULT = [
|
||||
self::HOURS_LONG,
|
||||
self::MINUTES_LONG,
|
||||
self::SECONDS_LONG,
|
||||
];
|
||||
|
||||
/**
|
||||
* @var string[]
|
||||
*/
|
||||
@@ -66,8 +72,11 @@ class Time extends DateTimeWizard
|
||||
* if you wish to use different separators, then they should be passed as an array.
|
||||
* If you want to use only a single format block, then pass a null as the separator argument
|
||||
*/
|
||||
public function __construct($separators, string ...$formatBlocks)
|
||||
public function __construct($separators = self::SEPARATOR_COLON, string ...$formatBlocks)
|
||||
{
|
||||
$separators ??= self::SEPARATOR_COLON;
|
||||
$formatBlocks = (count($formatBlocks) === 0) ? self::TIME_DEFAULT : $formatBlocks;
|
||||
|
||||
$this->separators = $this->padSeparatorArray(
|
||||
is_array($separators) ? $separators : [$separators],
|
||||
count($formatBlocks) - 1
|
||||
|
||||
@@ -13,7 +13,7 @@ class DateTest extends TestCase
|
||||
* @param null|string|string[] $separators
|
||||
* @param string[] $formatBlocks
|
||||
*/
|
||||
public function testDate(string $expectedResult, $separators, array $formatBlocks): void
|
||||
public function testDate(string $expectedResult, $separators = null, array $formatBlocks = []): void
|
||||
{
|
||||
$wizard = new Date($separators, ...$formatBlocks);
|
||||
self::assertSame($expectedResult, (string) $wizard);
|
||||
@@ -30,6 +30,8 @@ class DateTest extends TestCase
|
||||
['dddd dd.mm.yyyy', [Date::SEPARATOR_SPACE, Date::SEPARATOR_DOT], [Date::WEEKDAY_NAME_LONG, Date::DAY_NUMBER_LONG, Date::MONTH_NUMBER_LONG, Date::YEAR_FULL]],
|
||||
['dd-mm "in the year" yyyy', [Date::SEPARATOR_DASH, Date::SEPARATOR_SPACE], [Date::DAY_NUMBER_LONG, Date::MONTH_NUMBER_LONG, 'in the year', Date::YEAR_FULL]],
|
||||
["yyyy-mm-dd\u{a0}(ddd)", [Date::SEPARATOR_DASH, Date::SEPARATOR_DASH, Date::SEPARATOR_SPACE_NONBREAKING, null], [Date::YEAR_FULL, Date::MONTH_NUMBER_LONG, Date::DAY_NUMBER_LONG, '(', Date::WEEKDAY_NAME_SHORT, ')']],
|
||||
['yyyy-mm-dd', null, [Date::YEAR_FULL, Date::MONTH_NUMBER_LONG, Date::DAY_NUMBER_LONG]],
|
||||
['yyyy-mm-dd'],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ class TimeTest extends TestCase
|
||||
* @param null|string|string[] $separators
|
||||
* @param string[] $formatBlocks
|
||||
*/
|
||||
public function testTime(string $expectedResult, $separators, array $formatBlocks): void
|
||||
public function testTime(string $expectedResult, $separators = null, array $formatBlocks = []): void
|
||||
{
|
||||
$wizard = new Time($separators, ...$formatBlocks);
|
||||
self::assertSame($expectedResult, (string) $wizard);
|
||||
@@ -26,6 +26,8 @@ class TimeTest extends TestCase
|
||||
['hh:mm', Time::SEPARATOR_COLON, [Time::HOURS_LONG, Time::MINUTES_LONG]],
|
||||
["hh:mm\u{a0}AM/PM", [Time::SEPARATOR_COLON, Time::SEPARATOR_SPACE_NONBREAKING], [Time::HOURS_LONG, Time::MINUTES_LONG, Time::MORNING_AFTERNOON]],
|
||||
['h "hours and" m "minutes past midnight"', Time::SEPARATOR_SPACE, [Time::HOURS_SHORT, 'hours and', Time::MINUTES_SHORT, 'minutes past midnight']],
|
||||
['hh:mm:ss', null, [Time::HOURS_LONG, Time::MINUTES_LONG, Time::SECONDS_LONG]],
|
||||
['hh:mm:ss'],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user