parent
bd02cc79c7
commit
66cc5fbdc6
@ -0,0 +1,30 @@
|
||||
const getHours = (seconds) => {
|
||||
return Math.floor( seconds / 60 / 60 );
|
||||
}
|
||||
|
||||
const getMinutes = (seconds) => {
|
||||
return Math.floor( seconds / 60 );
|
||||
}
|
||||
|
||||
const createTimeObj = (seconds) => {
|
||||
const hours = getHours(seconds)
|
||||
let remainingSeconds = seconds - hours * 60 * 60
|
||||
const minutes = getMinutes(remainingSeconds)
|
||||
remainingSeconds -= minutes * 60
|
||||
return { hours, minutes, seconds: remainingSeconds }
|
||||
}
|
||||
|
||||
const getAccumulatedSeconds = (newerTime, olderTime) => {
|
||||
return Math.floor((newerTime-olderTime)/1000);
|
||||
}
|
||||
|
||||
const formatSeconds = (total, includeHours = false) => {
|
||||
const timeObj = createTimeObj(total)
|
||||
if(includeHours) {
|
||||
return `${timeObj.hours}:${timeObj.minutes.toString().padStart(2,'0')}:${timeObj.seconds.toString().padStart(2,'0')}`;
|
||||
} else {
|
||||
return `${timeObj.hours*60 + timeObj.minutes}:${timeObj.seconds.toString().padStart(2,'0')}`;
|
||||
}
|
||||
}
|
||||
|
||||
export { getHours, getMinutes, createTimeObj, getAccumulatedSeconds, formatSeconds }
|
||||
Loading…
Reference in new issue