import math


def pretty_duration(d):
    """Formats a time duration
    
    Formats a time duration in a human readable format
    
    Arguments:
        d {float} -- Duration in seconds
    
    Returns:
        str -- formated duration
    """

    if d < 1:
        return "<1s"

    s = ''
    
    days = math.floor(d / 86400)
    if days:
        s += f'{days}d '
    d = d % 86400

    hours = math.floor(d / 3600)
    if days or hours:
        s += f'{hours}h '
    d = d % 3600

    mins = math.floor(d / 60)
    if days or hours or mins:
        s += f'{mins}m '
    d = d % 60

    secs = round(d)
    if not days:
        s += f'{secs}s'

    return s.strip()