Re: Add __toString() to DateInterval

From: Date: Tue, 16 Mar 2021 19:04:33 +0000
Subject: Re: Add __toString() to DateInterval
References: 1 2 3 4 5 6 7  Groups: php.internals 
Request: Send a blank email to internals+get-113574@lists.php.net to get a copy of this message
On 16/03/2021 18:56, Moritz Friedrich wrote:
Again, I’m not attached to __toString(). Having another helper method or a special formatting constant, as suggested by others in this thread, would likewise be a viable option. I’d merely prefer to have a built-in way of parsing*and* composing time intervals as per the ISO specification, making the API consistent and easing communication with non-PHP systems.
Would a reasonable way forward be to have such a named method, and have it throw an exception if the instance is not representable in that form? That way, you'd be guaranteed that new DateInterval($period->toIsoPeriodString()) would result in an equivalent object, rather than discarding special relative values. Regards, -- Rowan Tommins [IMSoP]

Thread (19 messages)

« previous php.internals (#113574) next »