1
0
mirror of https://github.com/rlanvin/php-rrule.git synced 2024-11-28 05:24:10 +01:00

correctly parse DateTimeImmutable

This commit is contained in:
Alexandru Busuioc 2023-04-27 17:15:01 +01:00 committed by Rémi Lanvin
parent f7bcad3538
commit 38ea18eb55
2 changed files with 29 additions and 2 deletions

View File

@ -212,7 +212,7 @@ trait RRuleTrait
$date = new \DateTime($date->format('Y-m-d H:i:s'), $date->getTimezone());
}
else {
$date->setTime(
$date = $date->setTime(
$date->format('H'),
$date->format('i'),
$date->format('s'),
@ -222,4 +222,4 @@ trait RRuleTrait
return $date;
}
}
}

View File

@ -3238,4 +3238,31 @@ class RRuleTest extends TestCase
$expected = extension_loaded('intl') ? $withIntl : $withoutIntl;
$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],
];
}
}