import re


def format_time(time: str) -> str:
    """Helper function that returns the formatted time."""
    msecs = None
    ret_string = ''
    time_formats = ['secs', "mins", "hrs", 'days']

    if '.' in time:     # Creates an msec var if present in the time
        time_list = time.split('.')
        time, msecs = time_list[0], time_list[1]
    times = re.findall(r'\d+', time)

    if msecs is not None:
        times[-1] = times[-1] + f'.{msecs[:-1]}'
    index = 0
    for item in reversed(times):
        ret_string = f'{item} {time_formats[index]}, {ret_string}'
        index += 1
    return ret_string[:-2]