Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:113532 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 20441 invoked from network); 15 Mar 2021 09:24:37 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 15 Mar 2021 09:24:37 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 8ADB01804D1 for ; Mon, 15 Mar 2021 02:18:05 -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=0.8 required=5.0 tests=BAYES_20,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 ; Mon, 15 Mar 2021 02:18:04 -0700 (PDT) Received: from localhost (localhost [IPv6:::1]) by xdebug.org (Postfix) with ESMTPS id 0399310C030; Mon, 15 Mar 2021 09:18:03 +0000 (GMT) Date: Mon, 15 Mar 2021 09:18:03 +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-1582748554-1615799884=:2842" Subject: Re: [PHP-DEV] Add __toString() to DateInterval From: derick@php.net (Derick Rethans) --8323329-1582748554-1615799884=:2842 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: QUOTED-PRINTABLE On Wed, 3 Mar 2021, Moritz Friedrich wrote: > I would like to propose adding a `__toString()` method to the=20 > `DateInterval` class that should return a valid ISO8601 interval=20 > (https://en.wikipedia.org/wiki/ISO_8601#Time_intervals). As it stands,=20 > the class supports creating instances from such interval strings=20 > passed to its constructor, but the reverse isn=E2=80=99t true: The only w= ay to=20 > build a string representation of the interval is by querying the=20 > `DateInterval::format` method for the individual durations multiple=20 > times (see=20 > https://stackoverflow.com/questions/33787039/format-dateinterval-as-iso86= 01#answers=20 > for examples). The DateInterval class can also contain intervals that can't be=20 represented with such an ISO string. For example, how are you going to=20 do: $dt =3D DateInterval::createFromDateString( "next weekday" ); or $dt =3D DateInterval::createFromDateString( 'next Monday 02:00' ); __toString needs to work in every case, and I don't think you can do=20 that with ISO 8601 interval strings. 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-1582748554-1615799884=:2842--