def duration(duration, compact=False, unit=False):
    """Returns a time duration string representing the input value

    :param duration: value to format, must be convertible into an into
    :param compact: whether to show also seconds, defaults to False
    :param unit: whether to display he unit, defaults to False

    :return: duration representation (e.g. 5:02s) of the input value
    :rtype: string
    """
    duration = int(duration)
    if duration < 0:
        return "n/a"
    minutes, seconds = divmod(duration, 60)
    hours, minutes = divmod(minutes, 60)
    suf = "m"
    res = "{:02d}:{:02d}".format(minutes, seconds)
    if hours > 0:
        if compact:
            res = "{:02d}:{:02d}".format(hours, minutes)
        else:
            res = "{:02d}:{}".format(hours, res)
        suf = "h"

    return "{}{}".format(res, suf if unit else "")