Skip to content

Instantly share code, notes, and snippets.

@schadokar
Created August 5, 2019 11:20
Show Gist options
  • Select an option

  • Save schadokar/b49becfc0d6a44e872bd2581a57303e9 to your computer and use it in GitHub Desktop.

Select an option

Save schadokar/b49becfc0d6a44e872bd2581a57303e9 to your computer and use it in GitHub Desktop.
track your effective hours
const pee = (effHrs, effMins, lastInHrs, lastInMins, avgHrs, avgMins) => {
let totalEffMins = effHrs * 60 + effMins;
let avg = avgHrs * 60 + avgMins;
let diffInMins;
let leaveHrs;
let leaveMins;
const currentTime = new Date().toLocaleTimeString({
timeZone: "Asia/Kolkata"
});
let currentHrs = parseInt(currentTime.split(":")[0]);
let currentMins = parseInt(currentTime.split(":")[1]);
totalEffMins += (currentHrs - lastInHrs) * 60 + (currentMins - lastInMins);
if (avg >= totalEffMins) {
diffInMins = avg - totalEffMins;
leaveHrs = currentHrs + Math.floor(diffInMins / 60);
leaveMins = currentMins + (diffInMins % 60);
if (leaveMins >= 60) {
leaveHrs += 1;
leaveMins -= 60;
}
console.log(
`remaining hrs: ${Math.floor((avg - totalEffMins) / 60)}:${(avg -
totalEffMins) %
60} hrs:mins`,
`\nYou can safely pee at ${leaveHrs}:${leaveMins}`,
`\nTotal effective time: ${Math.floor(totalEffMins / 60)}:${totalEffMins %
60}`
);
} else {
diffInMins = totalEffMins - avg;
console.log(
`Extra hrs: ${Math.floor((totalEffMins - avg) / 60)}:${(totalEffMins -
avg) %
60} hrs:mins`,
`\nYou can leave at any time.`,
`\nTotal effective time: ${Math.floor(totalEffMins / 60)}:${totalEffMins %
60}`
);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment