Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:113567 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 66191 invoked from network); 16 Mar 2021 15:53:12 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 16 Mar 2021 15:53:12 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 2F71D180504 for ; Tue, 16 Mar 2021 08:47:00 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-1.1 required=5.0 tests=BAYES_00,SPF_HELO_PASS, SPF_NEUTRAL autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from xdebug.org (xdebug.org [82.113.146.227]) by php-smtp4.php.net (Postfix) with ESMTP for ; Tue, 16 Mar 2021 08:46:59 -0700 (PDT) Received: from localhost (localhost [IPv6:::1]) by xdebug.org (Postfix) with ESMTPS id 4349E10C030; Tue, 16 Mar 2021 15:46:58 +0000 (GMT) Date: Tue, 16 Mar 2021 15:46:58 +0000 (GMT) X-X-Sender: derick@singlemalt.home.derickrethans.nl To: Moritz Friedrich cc: internals@lists.php.net In-Reply-To: Message-ID: References: User-Agent: Alpine 2.23 (DEB 453 2020-06-18) MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="8323329-288718528-1615909618=:2842" Subject: Re: [PHP-DEV] Add __toString() to DateInterval From: derick@php.net (Derick Rethans) --8323329-288718528-1615909618=:2842 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: QUOTED-PRINTABLE On Tue, 16 Mar 2021, Moritz Friedrich wrote: > > I also don't understand what you're trying to say. You can't round=20 > > trip every interval as encoded in a DateInterval object through an=20 > > ISO interval string, so we shouldn't attempt to do that. >=20 > I think you do know what I=E2=80=99m trying to say, but choose to disagre= e=20 > with me. ISO interval strings allow to express arbitrary intervals of=20 > time as a string, so I don=E2=80=99t know what possible intervals you=E2= =80=99re=20 > referring to that purportedly cannot be encoded as an interval string. I already showed you that: "next weekday". It can either be +1 days, +2=20 days, or +3 days. > If this still revolves around relative intervals, then I don=E2=80=99t se= e=20 > your point either. The ISO interval specification is the most=20 > appropriate serialization format for time intervals as it is commonly=20 > used and well understood.=20 Maybe, but the DateInterval class does not represent a ISO interval=20 specification, it represents a timelib interval definition, which you=20 can *also* create from an ISO 8601 interval specification. > By choosing to serialize something like =E2=80=9Enext week=E2=80=9C to an= ISO=20 > interval, I=E2=80=99m willingly accepting the conversion to an absolute a= mount=20 > of time. If the specific start and end dates are relevant for the use=20 > case, an interval is not the appropriate tool, but keeping both dates=20 > is. That is not what a DateInterval object represents =E2=80=94 instead it=20 represents a definition how to get from one DateTime to another one. And that can not always be represented by an absolute amount. > Having a constructor that only accepts an ISO interval but no way to=20 > serialize the duration object back to an interval seems just like an=20 > inconsistent API to me. I=E2=80=99m not particularly attached to using=20 > `__toString()`, something like `toIsoInterval` or similar would do=20 > just as well. The only thing that annoys me here is a one-way parser=20 > for interval specs, deferring the serialization to userland PHP. Converting to just a simple string is not a serialisation, as it loses=20 information. If you care about serialisation, then you need to come up=20 with a way how to do that for every interval that a DateInterval can=20 represent. PHP's "serialize" can already serialise a DateInterval. cheers, Derick --=20 PHP 7.4 Release Manager Host of PHP Internals News: https://phpinternals.news Like Xdebug? Consider supporting me: https://xdebug.org/support https://derickrethans.nl | https://xdebug.org | https://dram.io twitter: @derickr and @xdebug --8323329-288718528-1615909618=:2842--