cakephp / chronos

A standalone DateTime library originally based off of Carbon
http://book.cakephp.org/chronos
MIT License
1.34k stars 61 forks source link

ChronosInterval #444

Open dereuromark opened 8 months ago

dereuromark commented 8 months ago

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 commented 8 months ago

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

markstory commented 8 months ago

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.

dereuromark commented 8 months ago

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

markstory commented 8 months ago

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.