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

Deprecate DateTimeImmutable #1928

Merged
merged 1 commit into from
Dec 5, 2024
Merged

Conversation

ruudk
Copy link
Contributor

@ruudk ruudk commented Nov 21, 2024

Fixes #1926

@Seldaek
Copy link
Owner

Seldaek commented Dec 5, 2024

Thanks

@InvisibleSmiley
Copy link
Contributor

FYI, citing https://semver.org/

Minor version Y (x.Y.z | x > 0) MUST be incremented if new, backward compatible functionality is introduced to the public API. It MUST be incremented if any public API functionality is marked as deprecated.

@ruudk ruudk deleted the date-time-immutable branch December 11, 2024 12:14
@Seldaek
Copy link
Owner

Seldaek commented Dec 11, 2024

Not sure what you're trying to say?

@InvisibleSmiley
Copy link
Contributor

New version should have been 3.9.0, not 3.8.1

@Seldaek
Copy link
Owner

Seldaek commented Dec 11, 2024

Ah I see. Yeah that was a mistake rushing this release while sitting at SymfonyCon.

$this->useMicroseconds = $useMicroseconds;

// if you like to use a custom time to pass to Logger::addRecord directly,
// call modify() or setTimestamp() on this instance to change the date after creating it
Copy link
Contributor

@glensc glensc Jan 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't immutable mean that you can't modify the instance?

I tested locally, and setTimestamp does nothing, I was expecting it to throw.

$ php -r '$t = new \DateTimeImmutable(); $t->setTimestamp(123); echo PHP_VERSION, "\n", $t->getTimestamp(), "\n";'

8.4.2
1735898810

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This class behaves the same as DateTime except new objects are returned when modification methods such as DateTime::modify() are called.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to use the instance returned by setTimestamp and pass that to Logger::addRecord as custom datetime instance.

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

Successfully merging this pull request may close these issues.

Rename Monolog\DateTimeImmutable to something else, e.g. JsonSerializableDateTimeImmutable
4 participants