import re


def format_pars_listing(pars):
    """Returns a formated list of pars.

    Args:
        pars (list): A list of PAR objects.

    Returns:
        The formated list as string
    """

    out = ""
    i = 1
    for p in pars:
        # Shorten to 30 chars max, remove linebreaks
        name = re.sub(r'[\n\r]', ' ',
                      p.name[:28] + '..'
                      if len(p.name) > 30
                      else p.name)
        obj_name = re.sub(r'[\n\r]', ' ',
                          p.object_name[:28] + '..'
                          if len(p.object_name) > 30
                          else p.object_name)
        time_cr = f"{p.time_created:%Y-%m-%d %H:%M}" \
            if p.time_created is not None else ""
        time_ex = f"{p.time_expires:%Y-%m-%d %H:%M}" \
            if p.time_expires is not None else ""

        out += (f"{i:>4} {name:30} {obj_name:30} {time_cr:16} {time_ex:16}\n")
        i += 1

    return out