
def stra(value):
    """
    Converts any value to a string. Replaces Python's stra() which incurs an error if the value
    happens to have a unicode character in it. Unicode characters will be replaced with ?

    :param any value: input value
    :return: value as string
    :rtype: str
    """
    # return str(value)
    return unicode(value).encode('ascii', 'replace')


def sanitize_elapsed_time(seconds):
    """
    Routine to convert a raw number of seconds into a human-friendly statement of duration

    :param seconds: number of seconds
    :return: formatted duration
    :rtype: str
    """

    if seconds < 120:
        str_elapsed_time = stra(int(seconds)) + ' seconds.'
    elif seconds < 3600:
        str_elapsed_time = stra(int(seconds)) + ' seconds (' + stra(round(seconds / 60, 1)) + ' minutes).'
    else:
        str_elapsed_time = stra(int(seconds)) + ' seconds (' + stra(round(seconds / 3600, 2)) + ' hours).'

    return str_elapsed_time
