Introduction
Time is a really simple concept. Seconds pass, one after the other, all the same. But humans love making it hard. This Stackoverflow question has gathered many answers and even though they are surprisingly long and complex, most of them will still fail for certain inputs. Can you format a number of seconds into a timestamp for human consumption not only precisely, but correctly?
Challenge
Build a human-readable timestamp from a floating point number of seconds. The timestamp must be formatted as hh:mm:ss.zzz
. Single digit hours, minutes and seconds must be formatted with a leading zero. If the number of complete hours is zero, the hours and leading colon must be omitted, making the output format mm:ss.zzz
. Please note that the number of hours may have more than two digits. For inputs that cannot be expressed as a finite number, the result must be --:--.---
(see below for examples of this that probably apply to your language). This is code-golf
, so the shortest code in bytes wins.
Example Input and Output
0 -> 00:00.000
-0 -> 00:00.000
1 -> 00:01.000
-1 -> -00:01.000
0.001 -> 00:00.001
3.141528 -> 00:03.142
3600 -> 01:00:00.000
3599.9995 -> 01:00:00.000
363600 -> 101:00:00.000
17999.9999 -> 05:00:00.000
Infinity -> --:--.---
-Infinity -> --:--.---
NaN -> --:--.---