Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:122896 X-Original-To: internals@lists.php.net Delivered-To: internals@lists.php.net Received: from php-smtp4.php.net (php-smtp4.php.net [45.112.84.5]) by qa.php.net (Postfix) with ESMTPS id 52AB41A009C for ; Tue, 2 Apr 2024 20:32:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1712089997; bh=OyjLO71yXSfD17JfE5JM/LCVpEWZgM46tPwrVhsHbqw=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=h65PTFiGBccYo+TUySpkCxHk6DVR6tPCPRVfnN3KR00x0iivuomhFlOsFAgYwBOWT 0HO2dge9PbVZPFQov7/UzGCb/xLFoZkh/OH0TN32xPbbcHFyqwWl0qAbhI0vordLoD HLENdkM4+vN+QjKooUF7L3Lk0yvqPazy08beTcFS8LjHYrDMbfnyHXK2EGKdG5CN2q srLOxoLn9E9NPP5+oypiwpK4cY3f2sdbtJHMSWTZy2SghDICESmvI8n6txh/Z0mhhK rr0KHKzFdxOasv7biq7gylQ5TEEEWT6pXfmaTBpRk3sziFTH1Gj2OwG62BfKHCAsGY u86WmDKJRdtLA== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 76CCA18078D for ; Tue, 2 Apr 2024 20:33:15 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on php-smtp4.php.net X-Spam-Level: * X-Spam-Status: No, score=1.1 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DMARC_MISSING,HTML_MESSAGE,HTML_OBFUSCATE_05_10, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from mail-lj1-f173.google.com (mail-lj1-f173.google.com [209.85.208.173]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Tue, 2 Apr 2024 20:33:15 +0000 (UTC) Received: by mail-lj1-f173.google.com with SMTP id 38308e7fff4ca-2d80baf621eso39550531fa.1 for ; Tue, 02 Apr 2024 13:32:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=scriptfusion-com.20230601.gappssmtp.com; s=20230601; t=1712089965; x=1712694765; darn=lists.php.net; h=in-reply-to:from:content-language:references:cc:to:subject :user-agent:mime-version:date:message-id:from:to:cc:subject:date :message-id:reply-to; bh=U/eG/SVea/vSB8g2KC8GORqK26J9jEzcCJGxaysL7bo=; b=oBgpqoSMqYAKXiQqytwqx6wNa69vFq+WIZAC53YE2LPuamZd8UVEtKk+IH3Hh693Pq yhEvytPa9iBM8iD+lJyRHrk3UEyC83jk3O685seDMM+1HvaSAouhNWI9UtUNsAlGzyVm +gN/6tW9XrIh5gJlQL67mI6m9nkCGtSaotq8SqgHehCqp4NGqrwR/QIa6a0brsLXFzI8 hShjXQN0ssi6JA0Xq0TVULPhVq/6HQbZ0471XUnOZl0RpxIS9J4Dhk2LKg8K93ojVFrd jyfO0j1CdyK5EaPozhODgnQn2jiFM2ph2uuaRnSXa3heyxmhi/o8PPboqhumn6KQNLvt g7KQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712089965; x=1712694765; h=in-reply-to:from:content-language:references:cc:to:subject :user-agent:mime-version:date:message-id:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=U/eG/SVea/vSB8g2KC8GORqK26J9jEzcCJGxaysL7bo=; b=THNJSbUbX7Jc8eiDu2yna+KOhMRxl9h8qLLlnJcqeTjdmspuJWt4BFzcWUTSTFbKzf vDssStpHzyu3Ds8FCk3GlzQD4UAvJwjoELKlHwEO+gSgj8AFdSrBaW1eSIEN4x3RWiLj IVGsqzqaFs0tTfqhojS6Qwcjb2SNXmJJ0d5jmHZsXQIfrLmGzr7+I0fsK5ieV6hMPFem DIx24XR3Kan9j8OxwbxOw2kVGSlhD+fb9MtelAjUWVmzdvmmQtjQ7g09pq/2Pm+TeGDi B4DuVdpdnkfuF3iU+OyzBQJEcgygs3mUd5tngLFN+c2h+xOuxXJHm6FZ74V5Q2skyGnS bM+g== X-Gm-Message-State: AOJu0YzMMKWTgD50mIJ5Zudj2S6pUUVbt0Cod5K5n3C5TVJiMWYaTwKY vcaRDpmH5JAVonyxxQq5RU3y5b+2xg1lPOR1FifkzPRV8BuHdos5eP7i2UUIO/uDrdccpI3o92b GaCI= X-Google-Smtp-Source: AGHT+IHUei2OV7ZRT3IBg0Un9v7gb2Tm/mpSNp6PT4s88+GM0kAivifxQPWpudERHOE9dhJLYKTMfg== X-Received: by 2002:a05:651c:140a:b0:2d6:f792:f4c4 with SMTP id u10-20020a05651c140a00b002d6f792f4c4mr386790lje.7.1712089964752; Tue, 02 Apr 2024 13:32:44 -0700 (PDT) Received: from ?IPV6:2a01:4b00:bf09:5101:e059:ee3c:206:2870? ([2a01:4b00:bf09:5101:e059:ee3c:206:2870]) by smtp.googlemail.com with ESMTPSA id f14-20020a05600c154e00b00414674a1a40sm19088104wmg.45.2024.04.02.13.32.44 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 02 Apr 2024 13:32:44 -0700 (PDT) Content-Type: multipart/alternative; boundary="------------gHzdzIYZYfSLV7tyji5E0mgZ" Message-ID: <98aafc64-4b78-4948-b2ba-6a36f22b9b67@scriptfusion.com> Date: Tue, 2 Apr 2024 21:32:43 +0100 Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PHP-DEV] First time contributor (DateTime::setDate PR) To: Derick Rethans Cc: internals@lists.php.net References: <31f7de10-a2dd-489e-bc2f-66987dc832aa@scriptfusion.com> Content-Language: en-GB In-Reply-To: From: bilge@scriptfusion.com (Bilge) This is a multi-part message in MIME format. --------------gHzdzIYZYfSLV7tyji5E0mgZ Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit On 02/04/2024 14:14, Derick Rethans wrote: > 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 >> 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 Hi Derick, Thanks for your reply! Indeed, as per your code snippet, this is a WTF moment I had not accounted for and confirm the same result with my patch applied. Generally, my expectation here would be the month *must* be set to 2, so if the day portion will be invalidated by that change, we should either throw an exception or implicitly coerce it into range, i.e. (new DateTime("2024-03-31"))->setDate(month: 2); == 2024-02-29. However, I suppose this is not the conversation we're having as you do not wish to change this API at all, which I respect. Regarding your brainstorm document, I can't understand much of it in its current state, and as I am not a subject matter expert, I think you will receive much better feedback from others. In particular, I cannot glean which four classes you are referring to in that document. Yet what I do find interesting is the notion of adding setters to DateTimeImmutable. For my particular use-case—producing a collection of dates incrementing by year in a Twig template—a trivial year setter would do just fine, with the significant caveat that it must implement fluent interface, because I need to call it in an expression context (returning a value), not a statement context (executing a void function separately). Not that Twig cannot execute statements, but it just becomes more verbose, cumbersome and less template-like. If you were happy for me to add getters and fluent setters for year, I'd be happy to work on that PR, but for month we're back to the same problem outlined in the opening paragraph (and I suppose the same problem occasionally applies to year, if the day happens to be set to the leap day). Otherwise, I'll be happy to read over your RFC when it's ready. Kind regards, Bilge --------------gHzdzIYZYfSLV7tyji5E0mgZ Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 8bit On 02/04/2024 14:14, Derick Rethans wrote:
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
Hi Derick,

Thanks for your reply!

Indeed, as per your code snippet, this is a WTF moment I had not accounted for and confirm the same result with my patch applied. Generally, my expectation here would be the month *must* be set to 2, so if the day portion will be invalidated by that change, we should either throw an exception or implicitly coerce it into range, i.e. (new DateTime("2024-03-31"))->setDate(month: 2); == 2024-02-29. However, I suppose this is not the conversation we're having as you do not wish to change this API at all, which I respect.

Regarding your brainstorm document, I can't understand much of it in its current state, and as I am not a subject matter expert, I think you will receive much better feedback from others. In particular, I cannot glean which four classes you are referring to in that document. Yet what I do find interesting is the notion of adding setters to DateTimeImmutable. For my particular use-caseproducing a collection of dates incrementing by year in a Twig templatea trivial year setter would do just fine, with the significant caveat that it must implement fluent interface, because I need to call it in an expression context (returning a value), not a statement context (executing a void function separately). Not that Twig cannot execute statements, but it just becomes more verbose, cumbersome and less template-like.

If you were happy for me to add getters and fluent setters for year, I'd be happy to work on that PR, but for month we're back to the same problem outlined in the opening paragraph (and I suppose the same problem occasionally applies to year, if the day happens to be set to the leap day). Otherwise, I'll be happy to read over your RFC when it's ready.

Kind regards, Bilge

--------------gHzdzIYZYfSLV7tyji5E0mgZ--