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.
  • Property-Based Tests Are the Guardrail Agents Need
    Example-based tests encode cases an agent can enumerate and hardcode past. Property-based tests quantify over inputs the agent did not see at code-write time, which is the gap that makes the lookup-table attack more expensive than the honest fix. Properties are one layer in the enforcement stack, not the whole stack.
  • The Contract Test Is the Only Witness the Agent Cannot Author
    A test the agent wrote against code the same agent wrote shares the agent's blind spot: a misunderstanding in the implementation becomes a matching misunderstanding in the test, the bar goes green, and the bug ships certified. Consumer-driven contract tests are the only category where a second team publishes the assertion the first team has to satisfy. That separation of authorship is exactly what tamper-resistant test design demanded, applied at the integration seam.