laminas-filter icon indicating copy to clipboard operation
laminas-filter copied to clipboard

Check for an instance of the `DateTimeInterface` instead of `DateTime` in `DateTimeFormatter`

Open kernusr opened this issue 2 years ago • 4 comments

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')));

kernusr avatar Jan 09 '23 10:01 kernusr

Is there some secret meaning in this?

Maybe because this interface did not exist back then?! :man_shrugging:

froschdesign avatar Jan 09 '23 11:01 froschdesign

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 👍

gsteel avatar Jan 09 '23 11:01 gsteel

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?

kernusr avatar Jan 09 '23 12:01 kernusr

Yes please.

Do add a test though.

Ocramius avatar Jan 09 '23 12:01 Ocramius