Re: [PHP-DEV] Add __toString() to DateInterval

2021-03-18 Thread Moritz Friedrich
> 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 discar

Re: [PHP-DEV] Add __toString() to DateInterval

2021-03-16 Thread Moritz Friedrich
> I already showed you that: "next weekday". It can either be +1 days, +2 > days, or +3 days. …depending on the time of execution, yes. The moment a developer consciously decides to transform an interval to an ISO string representation, they obviously accept the premise of anchoring the dynami

Re: [PHP-DEV] Add __toString() to DateInterval

2021-03-16 Thread Rowan Tommins
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 t

Re: [PHP-DEV] Add __toString() to DateInterval

2021-03-16 Thread Moritz Friedrich
> 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 string

Re: [PHP-DEV] Add __toString() to DateInterval

2021-03-16 Thread Derick Rethans
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,

Re: [PHP-DEV] Add __toString() to DateInterval

2021-03-16 Thread Derick Rethans
On Mon, 15 Mar 2021, Moritz Friedrich wrote: > 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 tru

Re: [PHP-DEV] Add __toString() to DateInterval

2021-03-15 Thread Moritz Friedrich
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

Re: [PHP-DEV] Add __toString() to DateInterval

2021-03-15 Thread Derick Rethans
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 su

Re: [PHP-DEV] Add __toString() to DateInterval

2021-03-03 Thread Moritz Friedrich
> Am 03.03.2021 um 14:01 schrieb Andreas Heigl : > > I'd rather see those classes as ValueObjects that should not have to > take care about their external representation. And a custom Formatter > that handles all the weird edge cases as a separate entity would be a > much easier to maintain app

Re: [PHP-DEV] Add __toString() to DateInterval

2021-03-03 Thread Chase Peeler
On Wed, Mar 3, 2021 at 8:42 AM Andreas Heigl wrote: > > Am 03.03.21 um 14:24 schrieb Moritz Friedrich: > > > > > >> Am 03.03.2021 um 14:01 schrieb Andreas Heigl : > >> > >> I'd rather see those classes as ValueObjects that should not have to > >> take care about their external representation. And

Re: [PHP-DEV] Add __toString() to DateInterval

2021-03-03 Thread Moritz Friedrich
Am 03.03.2021 um 11:53 schrieb Pierre : > > Le 03/03/2021 à 11:37, Moritz Friedrich a écrit : >> Hi internals, >> I’ve been active in the PHP ecosystem as @Radiergummi for quite a while now, >> but not on internals yet, so: nice to meet you all! >> >> I would like to propose adding a `__toString

Re: [PHP-DEV] Add __toString() to DateInterval

2021-03-03 Thread Larry Garfield
On Wed, Mar 3, 2021, at 4:37 AM, Moritz Friedrich wrote: > Hi internals, > I’ve been active in the PHP ecosystem as @Radiergummi for quite a while > now, but not on internals yet, so: nice to meet you all! > > I would like to propose adding a `__toString()` method to the > `DateInterval` class t

Re: [PHP-DEV] Add __toString() to DateInterval

2021-03-03 Thread Andreas Heigl
Am 03.03.21 um 14:24 schrieb Moritz Friedrich: > > >> Am 03.03.2021 um 14:01 schrieb Andreas Heigl : >> >> I'd rather see those classes as ValueObjects that should not have to >> take care about their external representation. And a custom Formatter >> that handles all the weird edge cases as a s

Re: [PHP-DEV] Add __toString() to DateInterval

2021-03-03 Thread Andreas Heigl
Hey Am 03.03.21 um 13:05 schrieb Hans Henrik Bergan: > if FWIW if DateTime::__toString() was just > function __toString():string{ > return $this->format(\DateTime::RFC3339); > } > > i certainly wouldn't complain. > > On Wed, 3 Mar 2021 at 12:16, Bruce Weirdan wrote: > >> On Wed, Mar 3, 202

Re: [PHP-DEV] Add __toString() to DateInterval

2021-03-03 Thread Pierre
Le 03/03/2021 à 13:05, Hans Henrik Bergan a écrit : if FWIW if DateTime::__toString() was just function __toString():string{ return $this->format(\DateTime::RFC3339); } i certainly wouldn't complain. On Wed, 3 Mar 2021 at 12:16, Bruce Weirdan wrote: Considering the replies, PHP Date(Tim

Re: [PHP-DEV] Add __toString() to DateInterval

2021-03-03 Thread Hans Henrik Bergan
if FWIW if DateTime::__toString() was just function __toString():string{ return $this->format(\DateTime::RFC3339); } i certainly wouldn't complain. On Wed, 3 Mar 2021 at 12:16, Bruce Weirdan wrote: > On Wed, Mar 3, 2021 at 1:07 PM Moritz Friedrich wrote: > > > but I’m not too fond of the c

Re: [PHP-DEV] Add __toString() to DateInterval

2021-03-03 Thread Bruce Weirdan
On Wed, Mar 3, 2021 at 1:07 PM Moritz Friedrich wrote: > but I’m not too fond of the constant - all other built-in date constants > translate to a string of plain format characters, which isn’t possible in > this case Adding another format character (similar to %c used by DateTimeInterface::for

Re: [PHP-DEV] Add __toString() to DateInterval

2021-03-03 Thread Pierre
Le 03/03/2021 à 11:37, Moritz Friedrich a écrit : Hi internals, I’ve been active in the PHP ecosystem as @Radiergummi for quite a while now, but not on internals yet, so: nice to meet you all! I would like to propose adding a `__toString()` method to the `DateInterval` class that should return