Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check for an instance of the DateTimeInterface instead of DateTime in DateTimeFormatter #96

Open
kernusr opened this issue Jan 9, 2023 · 4 comments
Labels
Bug Something isn't working

Comments

@kernusr
Copy link

kernusr commented Jan 9, 2023

Bug Report

Q A
Version(s) 2.30.0

Summary

Why are you checking for an instance of the DateTime and not a DateTimeInterface?

if (! is_string($value) && ! is_int($value) && ! $value instanceof DateTime) {

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 kernusr added the Bug Something isn't working label Jan 9, 2023
@froschdesign
Copy link
Member

Is there some secret meaning in this?

Maybe because this interface did not exist back then?! 🤷‍♂️

@gsteel
Copy link
Member

gsteel commented Jan 9, 2023

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 👍

@kernusr
Copy link
Author

kernusr commented Jan 9, 2023

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?

@Ocramius
Copy link
Member

Ocramius commented Jan 9, 2023

Yes please.

Do add a test though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants