After being converted from a salaried to an hourly employee, I found myself wanting to make mid-week evaluations
to determine if I was ahead or behind in my accumulation of hours for the week.
Because manually performing those calculations can be time consuming and error prone I wrote this time card calculator to help myself.
This example uses the JavaScript programming language to create an online time card calculator you can use from a web browser.
If you would like to see how to use JavaScript
for similar problem solving I recommend good book, like
this one.
If you are looking for more time card related resources,
click here.
Writing the timecard calculator
Here are the tasks that the calculator will need to tackle.
Get user input for start and stop times and a lunch adjustment.
Convert the start and stop hours into 24 hour format.
Convert the minutes from 60 to 100.
Subtract the converted start time from the converted stop time.
Subtract the lunch adjustment.
Display the total hours.
We'll repeat this process for each day, represented by a row in the calculator below.
The online timecard calculator -- Try Me!
Notes from JavaScript Time Card Calculator Project
Testing to validate your logic
It's important to define test cases to validate (or invalidate) your approach to solving the problem.
Here are the cases I used:
(a common base case)
(confirm minutes calculate correctly)
(a test case that doesn't cross AM/PM boundary)
(a weird case, probably error if entered, but sanity check)
(PM to AM boundary case A)
(AM to PM boundary case B)
(another weird case, but sanity check)
(another weird case, but sanity check)
(AM to PM boundary case B)
(AM to PM sanity check)
(PM to AM sanity check)
(graveyard shift)
(a case my initial tool miscalculated--oops, sorry about that)
Keywords: javascript time card calculator timecard esqsoft timesheet time sheet calculator 12 hour clock