Hi. I created fork of this library that use DateTimeInterface and extends both DateTime and DateTimeImmutable.
https://github.com/meebio/Carbon
Carbon library fork that extends both DateTime and DateTimeImmutable extensions with shared interface.
Original Carbon class is broken into CarbonInterface (interface extending DateTimeInterface) and CarbonTrait that implements that interface. There are 2 usable classes Carbon extending DateTime (that has exactly the same functionality as original Carbon class) and CarbonImmutable extending DateTimeImmutable. Both classes implement CarbonInterface and use CarbonTrait for common methods.
What are your thoughts about it? What can be improved?
Related issues: #103 #2 #233
You should allow issues on your fork IMO.
My question would be: Should it also have a bool isMutable() check for both classes to detect at runtime whether it is mutable or not? Would in some cases help for dynamically created objects to know what course of action to take.
@dereuromark
I enabled issues on my fork. Thanks for pointing that out :)
Method isMutable() totally makes sense, isImmutable() can be added too.
I didn't mention that, but there are two conversion methods added to one for each implementation: CarbonMutable has toImmutable() and CarbonImmutable has toMutable().
I think having one with boolean result might suffice :)
hi all,
hi bump this issues. it's possible to merge advance in this subject?
Thanks in advance.
@ektarum Hi
I can probably make new clean fork, that will be backward compatible (so easily mergeable). I'm not sure how to organize tests to not duplicate code. Hope it will be then accepted.
I created new fork and reimplemented changes trying to preserve as much backward compatibility as it is possible. I also added pull requests here: #426.
@jan-j Your changes have also been implemented in https://github.com/cakephp/chronos - just a heads up.
The general idea here is good but needs to obviously be in a v2.
@briannesbitt Do you actually have any plans for a v2, with immutability? Just curious where you're at.
Is there already a release for the immutable version?
@arjasco, for my needs which are nothing more than cloning, I use ->copy() before doing any modifying actions, for preserving the original Carbon object.
$today = Carbon::today(); // 2017-06-07 00:00:00
$someOtherDay = $today->copy()->addDays(8); // 2017-06-15 00:00:00
echo $today; // will output: 2017-06-07 00:00:00
I close as it seems this fork is no longer maintained.
Most helpful comment
@briannesbitt Do you actually have any plans for a v2, with immutability? Just curious where you're at.