On Tue, 16 Mar 2021, Moritz Friedrich wrote: > > 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.
I already showed you that: "next weekday". It can either be +1 days, +2 days, or +3 days. > 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. Maybe, but the DateInterval class does not represent a ISO interval specification, it represents a timelib interval definition, which you can *also* create from an ISO 8601 interval specification. > 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. That is not what a DateInterval object represents — instead it 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 > 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. Converting to just a simple string is not a serialisation, as it loses information. If you care about serialisation, then you need to come up with a way how to do that for every interval that a DateInterval can represent. PHP's "serialize" can already serialise a DateInterval. cheers, Derick -- 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
-- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: https://www.php.net/unsub.php