Any calculator that scores a timed event has the same quiet problem: people type times in five different ways. One person types 14:30 . Another types 870 . A third types 14.30 and means fourteen minutes and thirty seconds. If your parser guesses wrong, the score is wrong, and the user usually cannot tell.
This post walks through a small, boring approach that has held up well for me when building fitness-test calculators: accept a few clearly defined formats, reject everything else with a helpful message, and compare times as whole seconds.
Decide what you accept, and write it down
Before writing code, list the formats you will accept. Mine are:
mm:ss such as 14:30 or 9:05
m:ss with a single-digit minute
h:mm:ss for very long events, such as 1:02:15
plain seconds such as 870 , only when the field is labelled as seconds
Everything else is an error. That includes 14.30 , 14,30 , and 14m30s .…