laminas-filter
laminas-filter copied to clipboard
Check for an instance of the `DateTimeInterface` instead of `DateTime` in `DateTimeFormatter`
Bug Report
Q | A |
---|---|
Version(s) | 2.30.0 |
Summary
Why are you checking for an instance of the DateTime
and not a DateTimeInterface
? https://github.com/laminas/laminas-filter/blob/97e3ce0fa868567aa433ed34d6f57ee703d70d3e/src/DateTimeFormatter.php#L89
Is there some secret meaning in this?
Current behavior
In my application, there may be a situation when I create a DateTimeImmutable
and pass it in a DateTimeFormatter
,
expected a formatted string od date/time in return, but get my object back
How to reproduce
$filter = new DateTimeFormatter();
$date = new DateTimeImmutable($inputDate, $inputTimezone);
$start_date = $filter->filter($date->add(new \DateInterval('PT1H')));
$end_date = $filter->filter($date->add(new \DateInterval('PT7H')));
Is there some secret meaning in this?
Maybe because this interface did not exist back then?! :man_shrugging:
Can confirm that back in 2013, we were dealing with 5.3! Amazed this hasn't been discovered before.
A patch would be great @kernusr 👍
Is there some secret meaning in this?
Maybe because this interface did not exist back then?! 🤷♂️
The interface was added in php 5.5 and I'm surprised that no one noticed this in a rapidly developing project
So I can easily create a PR?
Yes please.
Do add a test though.