def METHOD_NAME(self, time):
    """
    This function parses user input when setting
    start of the day in general preferences.
    input:  @time               user's input as string
    output: @hour               default format for hours
            @minute             default format for minutes
            @ValueError         raised if @time is not valid
    """
    time = time.strip()
    invalid_format = False
    # Format for HH:MM and optional am/pm
    match = re.match(r'^(?P<hour>[0-9]{1,2}):?(?P<minute>[0-9]{2})?'
                     r' ?(?P<am_pm>[ap]m)?$', time.lower())
    if match:
        hour = int(match.group('hour'))
        minute = int(match.group('minute') or 0)
        am_pm = match.group('am_pm')
        if am_pm == 'am' and int(hour) == 12:
            hour = 0
        elif am_pm == 'pm':
            if 0 < int(hour) < 12:
                hour = hour + 12
            elif hour == 12:
                hour = 12
            elif hour > 12:
                invalid_format = True
        if not invalid_format:
            return datetime.time(int(hour), int(minute))
        else:
            raise ValueError('This time value or format\
                             is not allowed: {0}'.format(time))
    else:
        # The final attempt to parse the input
        return datetime.datetime.strptime(time, '%X')