@staticmethod
def date_diff_format(print_format, duration, sign):
    """Format a duration."""
    if print_format:
        delta_lookup = {'y': duration.years, 'm': duration.months, 'd':
            duration.days, 'h': duration.hours, 'M': duration.minutes, 's':
            duration.seconds}
        expression = ''
        for item in print_format:
            if item not in delta_lookup:
                expression += item
            elif float(delta_lookup[item]).is_integer():
                expression += str(int(delta_lookup[item]))
            else:
                expression += str(delta_lookup[item])
        return sign + expression
    else:
        return sign + str(duration)
