I have an array like this,
[
{id: 1, name: "sleep", endTime: 1600261550535, startTime: 1600261541729}, // 9 sec
{id: 2, name: "sleep", endTime: 1600261527833, startTime: 1600261522709}, // 5 sec
{id: 3, name: "sleep", endTime: 1600261496881, startTime: 1600261437616}, // 59 sec
{id: 4, name: "awake", endTime: 1600261427129, startTime: 1600261413596}, // 14 sec
{id: 5, name: "awake", endTime: 1600261403114, startTime: 1600261347569}, // 56 sec
{id: 6, name: "awake", endTime: 1600261337893, startTime: 1600261206497}, // 2 min 11 sec
]
I need to work out the the total time(duration) when all of the object with the same name
are added together. The time format should be in hr, min, sec.
Obviously it's easy to get the duration of one of them at a time but I cant think a way to add up duration of together.
Help is much appreciated. Thanks. Feel free to use moment or lodash
Output should be
total duration sleep : 1 min 13 secs
total duration awake : 3 min 21 secs
Edit: Thank you all so much for your response, You guys are what makes the community better.