I am working on a project using Angular JS 8 and I am willing to simplify the work I am doing a little bit. Here is the deal:
I am retrieving data from the backend as follows:
[{
"id": "1",
"start_time": "2020-01-12T10:00:000Z",
"end_time": "2020-01-12T12:00:000Z"
},
{
"id": "2",
"start_time": "2020-01-15T11:30:000Z",
"end_time": "2020-01-15T14:00:000Z"
},
{
"id": "3",
"start_time": "2020-01-19T12:00:000Z",
"end_time": "2020-01-19T18:40:000Z"
}]
I need to display the difference between end_time and start_time in a plain table, something like this:
id | start - end (time)
1 | 2 hours and 00 min
2 | 2 hours and 30 min
3 | 6 hours and 40 min
I am using moment.js in my controller to calculate the difference between these two dates but I am wondering if there is a better way to do it directly in the HTML, instead of iterating the retrieved data and performing this operation.