Created
August 5, 2019 11:20
-
-
Save schadokar/b49becfc0d6a44e872bd2581a57303e9 to your computer and use it in GitHub Desktop.
track your effective hours
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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