def formatInterval(secs, fmt):
    """Format an interval of length secs seconds according to format string
    fmt.

    fmt may contain labeled references {h}, {m} and {s} for hours, minutes
    and seconds. e.g. fmt = '{h:d}:{m:02d}:{s:02d}'"""
    try:
        secs = int(secs)
    except (TypeError, ValueError):
        return None
    if not 0 < secs < 5184000:        # 60 days
        return '<unknown>'
    mins, secs = divmod(secs, 60)
    hours, mins = divmod(mins, 60)
    return fmt.format(h=hours, m=mins, s=secs)