have manual time inputs match timer

practiced-songs
Matthew Huntington 1 year ago
parent 553a128468
commit 25c21f3cca

@ -9,18 +9,29 @@
}
}
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) => {
const minutes = getMinutes(total);
const seconds = total - minutes*60;
return `${minutes}:${padDigits(seconds)}`;
const timeObj = createTimeObj(total)
return `${timeObj.hours*60 + timeObj.minutes}:${padDigits(timeObj.seconds)}`;
}
export default {
@ -98,10 +109,16 @@
}
this.totalSeconds = getAccumulatedSeconds(Date.now(), this.startTime) - this.secondsToSubtract + this.savedPreviousSeconds;
this.setManualTime(this.totalSeconds)
window.localStorage.setItem('lastTotalSeconds', this.totalSeconds);
}, 1000);
},
setManualTime(seconds){
const timeObj = createTimeObj(this.totalSeconds)
this.manualHours = timeObj.hours
this.manualMinutes = timeObj.minutes
this.manualSeconds = timeObj.seconds
},
updateSavedPreviousSeconds(event){
this.savedPreviousSeconds = parseInt(event.target.value);
},
@ -163,6 +180,7 @@
this.categories = response.data
})
this.totalSeconds = parseInt(window.localStorage.getItem('lastTotalSeconds'))
this.setManualTime(this.totalSeconds)
this.savedPreviousSeconds = this.totalSeconds
window.onbeforeunload = this.confirmClose
},

Loading…
Cancel
Save