I would assume the moment I call some kind of ISO conversion or serialization 
method on a dynamic interval, I’d receive output relative to now. 
`createFromDateString` creates the interval relative to now, so why shouldn’t 
the reverse hold true?

Regards,
Moritz

> Am 15.03.2021 um 10:18 schrieb Derick Rethans <der...@php.net>:
> 
> On Wed, 3 Mar 2021, Moritz Friedrich wrote:
> 
>> I would like to propose adding a `__toString()` method to the 
>> `DateInterval` class that should return a valid ISO8601 interval 
>> (https://en.wikipedia.org/wiki/ISO_8601#Time_intervals). As it stands, 
>> the class supports creating instances from such interval strings 
>> passed to its constructor, but the reverse isn’t true: The only way to 
>> build a string representation of the interval is by querying the 
>> `DateInterval::format` method for the individual durations multiple 
>> times (see 
>> https://stackoverflow.com/questions/33787039/format-dateinterval-as-iso8601#answers
>>  
>> for examples).
> 
> The DateInterval class can also contain intervals that can't be 
> represented with such an ISO string. For example, how are you going to 
> do:
> 
> $dt = DateInterval::createFromDateString( "next weekday" );
> 
> or
> 
> $dt = DateInterval::createFromDateString( 'next Monday 02:00' );
> 
> __toString needs to work in every case, and I don't think you can do 
> that with ISO 8601 interval strings.
> 
> 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

Reply via email to