NodeJS tool to check timesheet and work hours
This NodeJS script is used to check my timesheet.
It allows to be sure that the expected weekly hours are done properly and if there is extra or missing time, it can be move properly to the next week.
You can enter the expected time for a week using the HOUR:MINUTE
format and the same for the actual time done.
Then it will compare the hours and minutes, check the difference and print it on the console.
const {
secondsToMinutes,
hoursToSeconds,
minutesToSeconds,
secondsToHours
} = require('date-fns');
const expected = '37:30'
const t = expected.split(':');
const expectedSeconds = hoursToSeconds(t[0]) + minutesToSeconds(t[1])
const actual = '39:00'
const a = actual.split(':');
const actualSeconds = hoursToSeconds(a[0]) + minutesToSeconds(a[1])
let symbol = ""
let time = secondsToMinutes(actualSeconds - expectedSeconds)
let diff = `${secondsToHours(actualSeconds - expectedSeconds)}:${secondsToMinutes(actualSeconds - expectedSeconds) % 60}`
if (actualSeconds < expectedSeconds) {
symbol = "Missing"
time = secondsToMinutes(expectedSeconds - actualSeconds)
diff = `${secondsToHours(expectedSeconds - actualSeconds)}:${secondsToMinutes(expectedSeconds - actualSeconds) % 60}`
}
console.log(`You've worked ${actual} / ${expected}`)
console.log(`Difference : ${symbol} ${time} Minute(s)`)
console.log(`Difference : ${symbol} ${diff}`)
Installation
The only dependency is date-fns
.
npm init -y
npm install -s date-fns
Usage
Update the expected
to set the time you must do per week, in this case it is define to 37:30
.
Than set the actual
time you did, in this case 39:00
.
The output will be :
You've worked 39:00 / 37:30
Difference : 90 Minute(s)
Difference : 1:30
In that case you did 1h30m in extra.
If you did not reach the expected time
expected = '37:30'
actual = '34:45'
The output will be :
You've worked 34:45 / 37:30
Difference : Missing 165 Minute(s)
Difference : Missing 2:45
In this case your are missing 2h45m