Well since we're making up answers here's a "solution" that doesn't use regexes:
In [3]: def weird_time_format(fmt): ...: fmt = str(fmt) ...: hours = fmt[:2].ljust(2, '0') ...: mins = fmt[2:4].ljust(2, '0') ...: secs = fmt[4:6].ljust(2, '0') ...: return ':'.join((hours, mins, secs)) ...: In [4]: weird_time_format(212812) Out[4]: '21:28:12'
This takes advantage of the fact that string slices are nice about out-of-bound indexes and return an empty string rather than throwing an error:
In [1]: ''[1:2] Out[1]: '' In [2]: ''[1:2].ljust(2, '0') Out[2]: '00'
Here's the results for your example input:
In [5]: example_input = (212812, 218654, 232527, 235959, 0, 181240, 25959, 153834) In [6]: tuple(map(weird_time_format, example_input)) Out[6]: ('21:28:12', '21:86:54', '23:25:27', '23:59:59', '00:00:00', '18:12:40', '25:95:90', '15:38:34')
And since I brought it up, what it does to 1234:
In [7]: weird_time_format(1234) Out[7]: '12:34:00'
OK, I felt (a little) bad for being facetious. If you're genuinely interested in this approach, this will work better and is more in line with the other answer's output:
In [3]: def weird_time_format(fmt): ...: fmt = str(fmt).rjust(6, '0') ...: return ':'.join((fmt[:2], fmt[2:4], fmt[4:6]))
1234?0become00:00:00, but25959only becomes2:59:59and not02:59:59?