Time Sheet Calculator
Level: Intermediate 30–60 minConcepts: 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
- 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.
- 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".
- C# (.NET 8, xUnit, FluentAssertions 6.12.0) — walkthrough
- TypeScript (Node 20, Vitest 1.6, TS 5 strict) — walkthrough
- Python (3.11, pytest) — walkthrough
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.