A dead simple time tracker that keeps everything in local storage. Next.js, no accounts and no server.
handcodedlocalstoragenextjsreactself-hostedserverlesstime-trackingtimer
1const timeDiff = (time) => {
2 const timeNow = new Date();
3 return timeNow - time;
4};
5
6const timeString = (timeDiff) => {
7 // timeDiff should be milliseconds
8 const timerTotal = [
9 timeDiff / 1000 / 60 / 60, // Hours (uncapped so long sessions don't wrap)
10 (timeDiff / 1000 / 60) % 60, // Minutes
11 (timeDiff / 1000) % 60, // Seconds
12 ];
13 return timerTotal
14 .map((timer) => {
15 let stringTime = Math.floor(timer).toString();
16 if (stringTime.length < 2) stringTime = `0${stringTime}`;
17 return stringTime;
18 })
19 .join(":");
20};
21
22export { timeDiff, timeString };