'Given the supplied val, val2, format and scale try to instantiate
the corresponding TimeFormat class to convert the input values into
the internal jd1 and jd2.
If format is `None` and the input is a string-type or object array then
guess available formats and stop when one matches.'

def _get_time_fmt(self, val, val2, format, scale, precision, in_subfmt, out_subfmt):

    if ((format is None) and (val.dtype.kind in (u'S', u'U', u'O'))):
        formats = [(name, cls) for (name, cls) in self.FORMATS.items() if issubclass(cls, TimeUnique)]
        err_msg = u'any    of    the    formats    where    the    format    keyword    is    optional    {0}'.format([name for (name, cls) in formats])
        formats.append((u'astropy_time', TimeAstropyTime))
    elif (not (isinstance(format, six.string_types) and (format.lower() in self.FORMATS))):
        if (format is None):
            raise ValueError(u'No    time    format    was    given,    and    the    input    is    not    unique')
        else:
            raise ValueError(u'Format    {0!r}    is    not    one    of    the    allowed    formats    {1}'.format(format, sorted(self.FORMATS)))
    else:
        formats = [(format, self.FORMATS[format])]
        err_msg = u'the    format    class    {0}'.format(format)
    for (format, FormatClass) in formats:
        try:
            return FormatClass(val, val2, scale, precision, in_subfmt, out_subfmt)
        except UnitConversionError:
            raise
        except (ValueError, TypeError):
            pass
    else:
        raise ValueError(u'Input    values    did    not    match    {0}'.format(err_msg))
