'Attempts to find date on a log line using templates.
This uses the templates\' `matchDate` method in an attempt to find
a date. It also increments the match hit count for the winning
template.
Parameters
line : str
Line which is searched by the date templates.
Returns
re.MatchObject, DateTemplate
The regex match returned from the first successfully matched
template.'

def matchTime(self, line):

    if (not len(self.__templates)):
        self.addDefaultTemplate()
    logSys.log((logLevel - 1), 'try    to    match    time    for    line:    %.120s', line)
    match = None
    ignoreBySearch = 2147483647
    i = self.__lastTemplIdx
    if (i < len(self.__templates)):
        ddtempl = self.__templates[i]
        template = ddtempl.template
        if (template.flags & (DateTemplate.LINE_BEGIN | DateTemplate.LINE_END)):
            if (logSys.getEffectiveLevel() <= (logLevel - 1)):
                logSys.log((logLevel - 1), '        try    to    match    last    anchored    template    #%02i    ...', i)
            match = template.matchDate(line)
            ignoreBySearch = i
        else:
            (distance, endpos) = (self.__lastPos[0], self.__lastEndPos[0])
            if (logSys.getEffectiveLevel() <= (logLevel - 1)):
                logSys.log((logLevel - 1), '        try    to    match    last    template    #%02i    (from    %r    to    %r):    ...%r==%r    %s    %r==%r...', i, distance, endpos, line[(distance - 1):distance], self.__lastPos[1], line[distance:endpos], line[endpos:(endpos + 1)], self.__lastEndPos[1])
            if ((line[(distance - 1):distance] == self.__lastPos[1]) and (line[endpos:(endpos + 1)] == self.__lastEndPos[1])):
                match = template.matchDate(line, distance, endpos)
        if match:
            distance = match.start()
            endpos = match.end()
            if ((template.flags & (DateTemplate.LINE_BEGIN | DateTemplate.LINE_END)) or ((distance == self.__lastPos[0]) and (endpos == self.__lastEndPos[0]))):
                logSys.log(logLevel, '        matched    last    time    template    #%02i', i)
            else:
                logSys.log(logLevel, '        **    last    pattern    collision    -    pattern    change,    search    ...')
                match = None
        else:
            logSys.log(logLevel, '        **    last    pattern    not    found    -    pattern    change,    search    ...')
    if (not match):
        logSys.log(logLevel, '    search    template    (%i)    ...', len(self.__templates))
        found = (None, 2147483647, 2147483647, (-1))
        i = 0
        for ddtempl in self.__templates:
            if (logSys.getEffectiveLevel() <= (logLevel - 1)):
                logSys.log((logLevel - 1), '        try    template    #%02i:    %s', i, ddtempl.name)
            if (i == ignoreBySearch):
                i += 1
                continue
            template = ddtempl.template
            match = template.matchDate(line)
            if match:
                distance = match.start()
                endpos = match.end()
                if (logSys.getEffectiveLevel() <= logLevel):
                    logSys.log(logLevel, '        matched    time    template    #%02i    (at    %r    <=    %r,    %r)    %s', i, distance, ddtempl.distance, self.__lastPos[0], template.name)
                if ((i + 1) >= len(self.__templates)):
                    break
                if (template.flags & (DateTemplate.LINE_BEGIN | DateTemplate.LINE_END)):
                    break
                if (((distance == 0) and ddtempl.hits) and (not self.__templates[(i + 1)].template.hits)):
                    break
                if ((distance > ddtempl.distance) or (distance > self.__lastPos[0])):
                    logSys.log(logLevel, '        **    distance    collision    -    pattern    change,    reserve')
                    if (distance < found[1]):
                        found = (match, distance, endpos, i)
                    match = None
                    i += 1
                    continue
                break
            i += 1
        if ((not match) and found[0]):
            (match, distance, endpos, i) = found
            logSys.log(logLevel, '        use    best    time    template    #%02i', i)
            ddtempl = self.__templates[i]
            template = ddtempl.template
    if match:
        ddtempl.hits += 1
        ddtempl.lastUsed = time.time()
        ddtempl.distance = distance
        if (self.__firstUnused == i):
            self.__firstUnused += 1
        self.__lastPos = (distance, line[(distance - 1):distance])
        self.__lastEndPos = (endpos, line[endpos:(endpos + 1)])
        if (i and (i != self.__lastTemplIdx)):
            i = self._reorderTemplate(i)
        self.__lastTemplIdx = i
        return (match, template)
    logSys.log(logLevel, '    no    template.')
    return (None, None)
