New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
3.0 - Extend DateTime to add a __toString and use that class instead when hydrating #2613
Comments
Sounds like |
Only that CakeTime does not extend DateTime and all the methods are static. |
I'm aware, but imo it would make sense to make CakeTime extend DateTime and make methods non static where it makes sense. e.g. TimeAgoInWords and all those do need to be static, they need a time anyway :) some of the methods can remain static, while other might as well work on an instance :) |
How would someone set the default format for this class? |
like today, either make them remain static or by passing it in through the constructor / set method |
@markstory Im thinking of using the |
@jippi I kind of like having Cake\Utility\Time be an extension of DateTime. I bet there are some interesting ideas hidden in doing that. |
After looking into / beginning to have Time extend DateTime, I wasn't seeing much value. For the most part, it's all static methods and there isn't much value outside of not having to instantiate a DateTime object inside of these methods. In my experiences, Time's role is primarily serving as the engine for the TimeHelper. (That's subject to myself though.) That being said, after bouncing this off of @markstory, he suggested having the ORM returning an improved DateTime object for Mark, please chime in if I've overlooked or misunderstood anything. |
Nope that was my thinking too. This would also allow us to provide a useful |
Maybe we can just use an external lib for this? https://github.com/briannesbitt/Carbon |
Using carbon might save us a bunch of time and effort. It has a pretty nice interface and the testing features are a bonus. |
Yeah, I particularly like the testing features which would solve one the nightmares from 2.x |
👍 for Carbon :=) |
Not only does it scratch our own itch, but it sets up application developers better as well. They too can benefit for the easier testing that carbon provides. |
Can this be closed with the Carbon dependency being used now? |
Yes |
According to some feedback I've got for 3.0-dev, doing
echo $entity->created
; throws an exception since the date object cannot be converted to string. Creating a class that extendsDateTime
and adding a__toString
method to it will solve this issue and make the views more visually appealing.We may consider adding some formatting shortcuts to it too.
The text was updated successfully, but these errors were encountered: