Week 7

Working 9 to 5

A pattern for two times, including morning and evening, turned into 24-hour form.

You type

A range of hours.

The tool
Two times become one 24-hour range A range Read both times 24-hour form
What comes out

The same range in 24-hour form, or the program stops when the range is not real.

The question, more slowly

The question is: a range of hours, possibly with am and pm, becomes the same range in 24-hour form. Nine in the morning stays 9. Nine in the evening becomes 21. A range that is not a real time, or not the shape the spec allows, and the program stops.

You are reading two times and a separator. Each time has an hour and optional minutes. Afternoon hours add 12, except 12 itself, which is its own case. Noon and midnight are the ones to write down before you code.

People add 12 to 12pm and get 24, or they leave 12am as 12. The spec's examples include both. Format the minutes even when the person left them out, if the spec shows that.

Before you code

Convert one afternoon hour to 24-hour time on paper. Noon and midnight are the tricky ones. The spec shows them.