mirror of
https://github.com/rlanvin/php-rrule.git
synced 2025-02-20 09:54:16 +01:00
correctly parse DateTimeImmutable
This commit is contained in:
parent
f7bcad3538
commit
38ea18eb55
@ -212,7 +212,7 @@ trait RRuleTrait
|
|||||||
$date = new \DateTime($date->format('Y-m-d H:i:s'), $date->getTimezone());
|
$date = new \DateTime($date->format('Y-m-d H:i:s'), $date->getTimezone());
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$date->setTime(
|
$date = $date->setTime(
|
||||||
$date->format('H'),
|
$date->format('H'),
|
||||||
$date->format('i'),
|
$date->format('i'),
|
||||||
$date->format('s'),
|
$date->format('s'),
|
||||||
|
@ -3238,4 +3238,31 @@ class RRuleTest extends TestCase
|
|||||||
$expected = extension_loaded('intl') ? $withIntl : $withoutIntl;
|
$expected = extension_loaded('intl') ? $withIntl : $withoutIntl;
|
||||||
$this->assertEquals($expected, $rrule->humanReadable($options));
|
$this->assertEquals($expected, $rrule->humanReadable($options));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var \DateTimeInterface|string
|
||||||
|
*
|
||||||
|
* @dataProvider dataForTestParseDate
|
||||||
|
*/
|
||||||
|
public function testParseDate($dateTime, \DateTimeInterface $expectedDateTime)
|
||||||
|
{
|
||||||
|
$parsed = RRule::parseDate($dateTime);
|
||||||
|
|
||||||
|
$this->assertEquals($expectedDateTime->format('U.u'), $parsed->format('U.u'));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return list<list<\DateTimeInterface|string>>
|
||||||
|
*/
|
||||||
|
public function dataForTestParseDate()
|
||||||
|
{
|
||||||
|
$dateTimeImmutableMicroseconds = new \DateTimeImmutable('2023-04-27 12:13:14.567');
|
||||||
|
$dateTimeImmutableNoMicroseconds = new \DateTimeImmutable('2023-04-27 12:13:14');
|
||||||
|
return [
|
||||||
|
['2023-04-27 12:13:14', new DateTime('2023-04-27 12:13:14')],
|
||||||
|
['2023-04-27 12:13:14.123', new DateTime('2023-04-27 12:13:14')],
|
||||||
|
[new DateTime('2023-04-27 12:13:14'), new DateTime('2023-04-27 12:13:14')],
|
||||||
|
[$dateTimeImmutableMicroseconds, $dateTimeImmutableNoMicroseconds],
|
||||||
|
];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user