def convert_24hour(time):
    """
    Takes 12 hour time as a string and converts it to 24 hour time.
    """

    if len(time[:-2].split(':')) < 2:
        hour = time[:-2]
        minute = '00'
    else:
        hour, minute = time[:-2].split(':')

    if time[-2:] == 'AM':
        time_formatted = hour + ':' + minute
    elif time[-2:] == 'PM':
        time_formatted = str(int(hour)+ 12) + ':' + minute

    if time_formatted in ['24:00','0:00','00:00']:
        time_formatted = '23:59'

    return time_formatted