<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def date_to_datetime(self, time_input, tz=None):
 """ Convert ISO 8601 and other date strings to datetime.datetime type. Args: time_input (string):
 The time input string (see formats above). tz (string):
 The time zone for the returned data. Returns: (datetime.datetime):
 Python datetime.datetime object. """

        dt = None
        try:
            # dt = parser.parse(time_input, fuzzy_with_tokens=True)[0]
            dt = parser.parse(time_input)
            # don't convert timezone if dt timezone already in the correct timezone
            if tz is not None and tz != dt.tzname():
                if dt.tzinfo is None:
                    dt = self._replace_timezone(dt)
                dt = dt.astimezone(timezone(tz))
        except IndexError:
            pass
        except TypeError:
            pass
        except ValueError:
            pass
        return dt