Time Sheet Calculator

Level: Intermediate 30–60 min

Concepts: Algorithms

Solutions: C# | TypeScript | Python


You are to develop a simple time sheet calculator application. It must take a start time in HH:mm format and an end time in HH:mm format. It must also take an optional break duration in HH:mm format to represent the duration of lunch. The result must be emitted in HH:mm format.

All times must be in 24-hour time format, no AM/PM.

Allow for users to invert the start and end times and still calculate the result properly.

Examples

Examples
Start Time : 08:42
End Time: 16:20
Break Duration : 00:30
Result : 07:08
Start Time : 17:02
End Time: 02:09
Break Duration : 00:35
Result : 08:32
Start Time : 07:02
End Time: 16:22
Result : 09:20

Hint

You may not use Timespan of other built-in DateTime capabilities to do this kata.

Bonus

  1. Allow for three and 4 digit numbers to be entered without needing a : to separate HH from mm. a. If three digits assume H:mm format.
  2. Allow for the user to input AM/PM instead of only using 24-hour time. E.g 08:00 AM

Reference Walkthrough

Reference implementations in C#, TypeScript, and Python live at tddbuddy-reference-katas/timesheet-calc. This is an F2 (light builder) kata: one primary entity (Timesheet), a typed Day enum distinguishing weekdays from the weekend, named constants for the overtime threshold and standard work week, a TimesheetTotals record whose totalHours is derived, and a test-folder TimesheetBuilder().WithEntry(day, hours).Build().

Scope note — weekly hour totals only. The original prompt above is a single-day HH:mm parser; the reference reframes the kata to its natural F2 shape — a weekly timesheet with daily and weekend overtime classification. HH:mm parsing, inverted/overnight times, 3-and-4-digit bonuses, AM/PM support, hourly pay rates, and PTO/holiday categories are deliberately out of scope for this reference and listed as stretch goals in the repo README. Those either return the kata to F1 string-parsing territory or tip it into F3 collaborator territory.

Overtime rules. Weekday hours beyond 8 are overtime. Weekend hours (Saturday / Sunday) are always overtime. A full Monday–Friday at 8 hours each produces the 40-hour standard work week with no overtime. Fractional hours are permitted; negative hours raise a language-idiomatic error with the cross-language-identical message "hours must not be negative".

This kata ships in Agent Full-Bake mode at middle gear, the F2 (light builder) tier. See the repo’s Gears section for why middle gear is the deliberate choice.


  • Katas Are Rehearsal, Not Performance
    You don't practice TDD on production code. You practice on katas and bring the muscle memory to production. The gap between knowing TDD and doing TDD is reps.
  • Test Deletion Is a Privileged Operation
    The cheapest way for an agent to make a failing test pass is to delete it. That is logical for the agent and catastrophic for the codebase. Tests are append-only by default. Deletion needs a human author, a separate commit, and a separate review.
  • Refactor Was Always Where Compounding Lived
    Red and green were the visible two thirds of TDD. Refactor was the optional polish. Codebases that compound did the refactor pass; codebases that accrete did not. Agents skip refactor by default because it has no green-bar reward, and a year of skipped refactors is how a codebase loses its shape.