def format_duration(duration):
    """
    Format duration from seconds to hours, minutes and seconds.

    Parameters:
    - duration : duration in seconds
    """
    if type(duration) not in (float, int) or duration < 0:
        return 'unknown'
    duration = round(duration)
    seconds = int(duration % 60)
    duration = duration / 60
    format_string = '{:d}s'.format(seconds)
    if duration >= 1:
        minutes = int(duration % 60)
        duration = duration / 60
        format_string = '{:d}m {:s}'.format(minutes, format_string)
        if duration >= 1:
            hours = int(duration % 60)
            format_string = '{:d}h {:s}'.format(hours, format_string)
    return format_string
