Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:113533 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 22083 invoked from network); 15 Mar 2021 09:29:35 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 15 Mar 2021 09:29:35 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id E10821804E3 for ; Mon, 15 Mar 2021 02:23:03 -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.7 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,SPF_HELO_PASS,SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from mail.hades.9dev.de (mail.hades.9dev.de [88.99.187.36]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Mon, 15 Mar 2021 02:23:03 -0700 (PDT) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id E9B1D5DDD0; Mon, 15 Mar 2021 10:22:58 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=9dev.de; s=dkim; t=1615800179; h=from:subject:date:message-id:to:cc:mime-version:content-type: content-transfer-encoding:in-reply-to:references; bh=k4gfxUnXvkXiI7D3qT8liaFKCBVlMAY7zURGSz/xuGg=; b=FzI9eNa95bvP0oFvv1D7sWEtkwSPT50v6aMv26t/gHPNHtY1gVO5AOAcoPvwpdZTfz0P59 JgodE2Yl0nmqEJLFOUK72oS1x7Gu20F9ASWQ8iPk7EKDYfjv2lfSWO9lUBzgUxdcxnWwSs vlNaJolV1+QWS3lBWYbYJCQ2CGCeWbQrYWPTxdZ3aXaZucCsBMV1E38gSyQIvkZm4o0YIs 7FA1TaZ9hZ+wxid5D6CVLgWeCDoE5wLuRsSIW7V72fkchwA1O8QKpPI8ZVkcGsjHCsnIds s49qAFlq4wW4LZ5bErpz5GKe5BHpHO0FH0GuD2GqXSSlYFI1IiJubdJyg/YsQA== Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 14.0 \(3654.60.0.2.21\)) In-Reply-To: Date: Mon, 15 Mar 2021 10:22:56 +0100 Cc: internals@lists.php.net Content-Transfer-Encoding: quoted-printable Message-ID: References: To: Derick Rethans X-Last-TLS-Session-Version: TLSv1.2 Subject: Re: [PHP-DEV] Add __toString() to DateInterval From: m@9dev.de (Moritz Friedrich) I would assume the moment I call some kind of ISO conversion or = serialization method on a dynamic interval, I=E2=80=99d receive output = relative to now. `createFromDateString` creates the interval relative to = now, so why shouldn=E2=80=99t the reverse hold true? Regards, Moritz > Am 15.03.2021 um 10:18 schrieb Derick Rethans : >=20 > On Wed, 3 Mar 2021, Moritz Friedrich wrote: >=20 >> 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 way 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-iso860= 1#answers=20 >> for examples). >=20 > 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: >=20 > $dt =3D DateInterval::createFromDateString( "next weekday" ); >=20 > or >=20 > $dt =3D DateInterval::createFromDateString( 'next Monday 02:00' ); >=20 > __toString needs to work in every case, and I don't think you can do=20= > that with ISO 8601 interval strings. >=20 > cheers, > Derick >=20 > --=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