def _linear_search_log_for_time(log_path, dt, word_count, lbound, ubound, reverse=False):
  """
  Find the start position of the line containing the datetime nearest to dt.
  :param log_path: the absolute path to the log file
  :param dt: the datetime to be searched
  :param word_count: the number of "words" that represents the datetime in the log
  :param lbound: the byte offset to the start of the block to be searched
  :param ubound: the byte offset to the end of the block to be searched
  :param reverse: if False, finds the line with the largest datetime less than dt
                  if True, finds the line with the smallest datetime larger than dt
  """
  with open(log_path, 'r') as log:
    log.seek(lbound)

    # The following are true at the beginning of each iteration:
    #   - line_start points to the beginning of the line of the datetime we are currently processing
    #   - prev_line_start points the beginning of the previous line (except for the first iteration)
    prev_line_start = lbound
    line_start = log.tell()
    while log.tell() < ubound:
      is_valid_dt = False

      # some lines may not begin with a valid datetime (e.g exception messages that spans multiple lines)
      # hence, we loop until we find a line with a valid datetime
      while not is_valid_dt:
        line = log.readline()
        timestr = ' '.join(line.split()[:word_count])
        try:
          log_dt = parser.parse(timestr)
          is_valid_dt = True
        except:
          is_valid_dt = False
          if log.tell() == ubound:
            if not reverse:
              return prev_line_start
            else:
              return log.tell()

      if not reverse:
        if log_dt >= dt:
          return prev_line_start
        else:
          prev_line_start = line_start
          line_start = log.tell()
          if line_start == ubound:
            # reached the end of block, return the last line
            return prev_line_start
      else:
        if dt > log_dt:
          return log.tell()
        else:
          if log.tell() == ubound:
            # reached the end of block, return the last line
            return log.tell()
          else:
            line_start = log.tell()
dataset/ETHPy150Open linkedin/Zopkio/zopkio/test_utils.py/_linear_search_log_for_time/swapped operands of `>`