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

Chronos::createFromFormat using a date without time does not respect Chronos::setTestNow #452

Open
holtkamp opened this issue Apr 11, 2024 · 2 comments

Comments

@holtkamp
Copy link

holtkamp commented Apr 11, 2024

It seems Chronos::setTestNow() only fixates the time and not the rest of a date, is that intended?

For example, when using Chronos::createFromFormat() with a partial format, things like the day and month are not fixated:

Chronos::setTestNow(new Chronos('2020-12-01 00:00:00'));
$date = Chronos::createFromFormat('m-d', '10-5'); // I would expect this to become "2020-10-05 00:00:00
$date = Chronos::createFromFormat('d', '5'); // I would expect this to become "2020-12-05 00:00:00

Note this is similar to briannesbitt/Carbon#1280

@othercorey
Copy link
Member

This is using the default behavior of DateTimeImmutalbe;:createFromFormat(). I don't think we'll be able to detect a time component wasn't included in the format.

@holtkamp
Copy link
Author

@othercorey thanks for the swift response. Indeed the native DateTimeImmutable::createFromFormat() does not support providing an alternative clock.

Maybe this can be used as inspiration: briannesbitt/Carbon#1281

Which seem to have landed here after 6 years: https://github.com/briannesbitt/Carbon/blob/8275fbf2f47c8a792cda010d56b7fe62c3eeafbb/src/Carbon/Traits/Creator.php#L602-L613

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants