def timedelta_to_string(timestamp):
    """
    Returns '0h', '0m' or '0h 0m' formatted string from given timedelta-type
    timestamp.
    """
    if timestamp.seconds // 3600 == 0:
        return str(timestamp.seconds // 60 % 60) + 'm'
    elif timestamp.seconds // 60 % 60 == 0:
        return str(timestamp.seconds // 3600) + 'h'

    return '{}h {}m'.format(str(timestamp.seconds // 3600),
                            str(timestamp.seconds // 60 % 60))