I'm creating a simple time tracker for time and motion study purposes in Google sheets. The current code that I'm using only records start time and end time as shown on the screenshot below.
[Time tracker]
What I would like to do is for it to have the ability to pause the timer and then have the ability to resume anytime.
Below is the current script/code I'm using (Credits to @Cooper who provided me this code in Automatically record start time, end time and total handling time in Google sheets:
function onEdit(e) {
const sh = e.range.getSheet();
if (sh.getName() == "Sheet1" && e.range.columnStart == 2 && e.value) {
e.range.offset(0, 7).setValue(new Date())
}
if (sh.getName() == "Sheet1" && e.range.columnStart == 8 && e.value) {
e.range.offset(0, 2).setValue(new Date());
let Start = new Date(sh.getRange(e.range.rowStart,8).getValue());
let End = new Date(sh.getRange(e.range.rowStart,9).getValue());
sh.getRange(e.range.rowStart,10).setValue(timeDiff1(Start,End));
}
}
function timeDiff1(Start, End) {
if (Start && End) {
var second = 1000;
var minute = 60 * second;
var t1 = new Date(Start).valueOf();
var t2 = new Date(End).valueOf();
var d = t2 - t1;
var minutes = Math.floor(d % day % hour / minute);
var seconds = Math.floor(d % day % hour % minute / second);
return 'mm:ss\n' + minutes + ':' + seconds;
}
else {
return 'Invalid Inputs';
}
}
Is this doable or is there an alternative code I can use?