I've got a model which has a getDate() getter method.
In the controller I defined a utility class called timeAgoUtil which calculates the time since that Date value, for example: 6 hours ago.
Now I need to access that utility method every time I want to get the value on screen, which is quite a lot. Most of the times on objects in a list, which requires me to loop through it to get each time ago value.
My approach:
- At the start of the model I defined the
timeAgoUtilutility class. - I created a new getter method to the model called
getTimeAgo(). - In that method I put
return timeAgoUtil.convert(this.date);.
Is manipulating the result before retuning it in a getter AND defining a utility class inside the model common use?