chronos icon indicating copy to clipboard operation
chronos copied to clipboard

ChronosInterval

Open dereuromark opened this issue 2 years ago • 5 comments

trigger_error( 'Since 2.4 ChronosInterval is deprecated. Use Chronos::createInterval() instead.', E_USER_DEPRECATED );

Why is that? The suggested method doesnt exist in the code

I would recommend we keep this method as it is useful and better than using the native DateInternal class and its methods. E.g. (string) casting to the native format is super important IMO.

I see that https://github.com/cakephp/chronos/commit/3449ecabecd5f029bec3342376b6a4c788b227f8 dropped it as there were some issues with the native class and compatibility.

I have the same issue when trying to actually create any kind of improved wrapper around it. Maybe instead of extending it, we could encapsulate it using the proxy pattern?

But according to e.g. https://github.com/pauci/datetime/blob/master/src/DateInterval.php it should work with extension.

dereuromark avatar Oct 26 '23 21:10 dereuromark

I sth like this viable? https://github.com/cakephp/chronos/compare/2.x...2.x-interval

dereuromark avatar Oct 26 '23 22:10 dereuromark

I have the same issue when trying to actually create any kind of improved wrapper around it. Maybe instead of extending it, we could encapsulate it using the proxy pattern?

Given how thorny datetime can be, I think the proxy/decorator pattern is the only good option we have. We could include a toNative() or toDateInterval method so that working with other libraries is reasonable.

markstory avatar Oct 27 '23 02:10 markstory

Downside is that the types on methods wouldnt work, if something expects a native one.

dereuromark avatar Oct 27 '23 03:10 dereuromark

Downside is that the types on methods wouldnt work, if something expects a native one.

Which is why we'd have a toNative() type method to provide compatibility with non-application code.

markstory avatar Nov 12 '23 05:11 markstory