Re: Add __toString() to DateInterval

From: Date: Tue, 16 Mar 2021 12:57:40 +0000
Subject: Re: Add __toString() to DateInterval
References: 1 2 3 4  Groups: php.internals 
Request: Send a blank email to internals+get-113561@lists.php.net to get a copy of this message

> I also don't understand what you're trying to say. You can't round trip 
> every interval as encoded in a DateInterval object through an ISO 
> interval string, so we shouldn't attempt to do that.


I think you do know what I’m trying to say, but choose to disagree with me. ISO interval strings
allow to express arbitrary intervals of time as a string, so I don’t know what possible intervals
you’re referring to that purportedly cannot be encoded as an interval string.
If this still revolves around relative intervals, then I don’t see your point either. The ISO
interval specification is the most appropriate serialization format for time intervals as it is
commonly used and well understood. By choosing to serialize something like „next week“ to an ISO
interval, I’m willingly accepting the conversion to an absolute amount of time. If the specific
start and end dates are relevant for the use case, an interval is not the appropriate tool, but
keeping both dates is.
Having a constructor that only accepts an ISO interval but no way to serialize the duration object
back to an interval seems just like an inconsistent API to me. I’m not particularly attached to
using __toString(), something like toIsoInterval or similar would do just
as well. The only thing that annoys me here is a one-way parser for interval specs, deferring the
serialization to userland PHP. 


Regards,
Moritz


Thread (19 messages)

« previous php.internals (#113561) next »