Re: First time contributor (DateTime::setDate PR)
| From: | Derick Rethans | Date: | Tue, 02 Apr 2024 13:14:43 +0000 |
| Subject: | Re: First time contributor (DateTime::setDate PR) | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-122855@lists.php.net to get a copy of this message | ||
Hi,
On Sun, 31 Mar 2024, Bilge wrote:
> About the PR: I sometimes find it would be useful to only update part of the
> date. The PR makes all parameters to DateTime(Immutable)::setDate
>
> <https://www.php.net/manual/en/datetimeimmutable.setdate.php>
> optional in a
> backwards-compatible manner such that we can elect to update only the day,
> month, year or any combination of the three (thanks, in part, to named
> parameters). Without this modification, we must always specify all of the day,
> month and year parameters to change the date.
As I mentioned to you in Room 11, I am not in favour of adhoc API
changes to Date/Time classes. It has now been nearly 18 years since they
were originally introduced, and they indeed could do with an overhaul.
I have been colllecting ideas in
https://docs.google.com/document/d/1pxPSRbfATKE4TFWw72K3p7ir-02YQbTf3S3SIxOKWsk/edit#heading=h.2jol7kfhmijb
Having different/better modifiers would also be a good thing to talk
about, albeit perhaps on the four mentioned new classes, instead of
adding them to the already existing DateTime and DateTimeImmutable
classes.
In any case, just allowing setDate to be able to just modify the month
is going to introduce confusion, as this will be counter intuitive:
$dt = new DateTimeImmutable("2024-03-31");
$newDt = $dt->setDate( month: 2 );
It is now representing 2024-03-02.
This might be the right answer, but it might also be that the developer
just cared about the month part (and not the day-of-month), in which
case this is a WTF moment.
Picking mofication APIs is not as trivial as it seems, and I would like
to do it *right*.
Feel free to add comments and wishes to the google doc document. In the
near future, I will be writing up an RFC from this.
cheers,
Derick
--
https://derickrethans.nl | https://xdebug.org | https://dram.io
Author of Xdebug. Like it? Consider supporting me: https://xdebug.org/support
mastodon: @derickr@phpc.social @xdebug@phpc.social