Am 03.03.21 um 14:24 schrieb Moritz Friedrich: > > >> Am 03.03.2021 um 14:01 schrieb Andreas Heigl <andr...@heigl.org>: >> >> 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 approach. And such a Formatter can easily be >> build in userland (I think I wrote one myself at one point) and so the >> maintenance-burden would also not be added to internals. >> >> That would also apply to the DateTimeInterval::format() method but that >> would mean a massive BC break so it is most likely out of the question. >> Nevertheless I would prefer an external library to handle all those >> formatting issues and treat the DateTime lib as internal ValueObjects > > I’d like to respectfully disagree. If we were to go down the ValueObject > route, DateTime/DateInterval should not be able to create new instances from > formatted strings in the first place. PHP Date classes have always been > intertwined with their output formatting however, so this is how the > ecosystem uses them. In that sense, I’d expect DateInterval to be able to > return the format it was instantiated with, but it isn't.
Well. ValueObjects should be able to create new Instances of themselves via factory methods. But that would mean a lot of tweaking at perhaps no added benefit. But TBH: DateTimeImmutable:fromString() instead of new DateTimeImmutable() would be awesome... Or even better: DateTime::fromString() with DateTimeImmutable as return type > The PHP API may have its warts, but I prefer my warts consistent. I feel you. As the other Objects have a format() method why not have a format method for DatePeriod as well? It does not need to take a parameter as there are no different formats (at least that I could think of). But I would rather not add more magic (methods) to PHP... Cheers Andreas -- ,,, (o o) +---------------------------------------------------------ooO-(_)-Ooo-+ | Andreas Heigl | | mailto:andr...@heigl.org N 50°22'59.5" E 08°23'58" | | https://andreas.heigl.org | +---------------------------------------------------------------------+ | https://hei.gl/appointmentwithandreas | +---------------------------------------------------------------------+
OpenPGP_signature
Description: OpenPGP digital signature