def list_occurrences(from, direction = :forward, &block)
      raise ArgumentError, "From #{from} not matching the rule #{@rule} and start time #{@start_time}" unless @rule.match?(from, @start_time)

      results = []

      n, current = init_loop(from, direction)
      loop do
        # Rails.logger.debug("Listing occurrences of #{@rule}, going #{direction.to_s}, current: #{current}")
        # break on schedule span limits
        return results unless (current >= @start_time) && (@rule.stop.nil? || current < @rule.stop) && (@rule.count.nil? || (n -= 1) >= 0)

        # break on block condition
        return results unless yield current

        results << current

        # step
        if direction == :forward
          current = @rule.next(current, @start_time)
        else
          current = @rule.previous(current, @start_time)
        end
      end
    end
def list_occurrences(from, direction = :forward, &block)
      raise ArgumentError, "From #{from} not matching the rule #{@rule} and start time #{@start_time}" unless @rule.match?(from, @start_time)

      results = []

      n, current = init_loop(from, direction)
      loop do
        # Rails.logger.debug("Listing occurrences of #{@rule}, going #{direction.to_s}, current: #{current}")
        # break on schedule span limits
        return results unless (current >= @start_time) && (@rule.stop.nil? || current < @rule.stop) && (@rule.count.nil? || (n -= 1) >= 0)

        # break on block condition
        return results unless yield current

        results << current

        # step
        if direction == :forward
          current = @rule.next(current, @start_time)
        else
          current = @rule.previous(current, @start_time)
        end
      end
    end
def list_occurrences ( from , direction = :forward , & block ) raise ArgumentError , "From #{from} not matching the rule #{@rule} and start time #{@start_time}" unless @rule . match? ( from , @start_time ) results = [ ] n , current = init_loop ( from , direction ) loop do # Rails.logger.debug("Listing occurrences of #{@rule}, going #{direction.to_s}, current: #{current}") # break on schedule span limits return results unless ( current >= @start_time ) && ( @rule . stop . nil? || current < @rule . stop ) && ( @rule . count . nil? || ( n -= 1 ) >= 0 ) # break on block condition return results unless yield current results << current # step if direction == :forward current = @rule . next ( current , @start_time ) else current = @rule . previous ( current , @start_time ) end end end
yields valid occurrences, return false from the block to stop
yields valid occurrences return false from the block to stop