Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Querying events using until returns empty list #37

Open
bbbneo333 opened this issue Oct 13, 2021 · 0 comments
Open

Querying events using until returns empty list #37

bbbneo333 opened this issue Oct 13, 2021 · 0 comments

Comments

@bbbneo333
Copy link

Problem: When querying for events on a recurrence having recurrence.until = date1, using recurrence.events(until: date2), where date2 >= date1, the second call to events will always fail.

Reproduce:

ruby recurring.rb -v v

# frozen_string_literal: true

require 'recurrence'
require 'test/unit'

class RecurrenceEventsTest < Test::Unit::TestCase
  def recurrence
    Recurrence.new(
      every: :week,
      on: %i[monday tuesday wednesday thursday],
      starts: '2021-10-01',
      until: '2021-10-10'
    )
  end

  # will pass
  test 'events without start_date, end_date' do
    recurrence_model = recurrence

    assert_equal recurrence_model.events, [Date.new(2021, 10, 4), Date.new(2021, 10, 5), Date.new(2021, 10, 6), Date.new(2021, 10, 7)]
    assert_equal recurrence_model.events, [Date.new(2021, 10, 4), Date.new(2021, 10, 5), Date.new(2021, 10, 6), Date.new(2021, 10, 7)]
  end

  # will pass
  test 'events with start_date, end_date within actual end_date' do
    recurrence_model = recurrence

    assert_equal recurrence_model.events(
      starts: '2021-10-04',
      until: '2021-10-06'
    ), [Date.new(2021, 10, 4), Date.new(2021, 10, 5), Date.new(2021, 10, 6)]
    assert_equal recurrence_model.events(
      starts: '2021-10-04',
      until: '2021-10-06'
    ), [Date.new(2021, 10, 4), Date.new(2021, 10, 5), Date.new(2021, 10, 6)]
  end

  # will fail, date2 = date1
  test 'events with start_date, end_date as actual end_date' do
    recurrence_model = recurrence

    assert_equal recurrence_model.events(
      starts: '2021-10-04',
      until: '2021-10-10'
    ), [Date.new(2021, 10, 4), Date.new(2021, 10, 5), Date.new(2021, 10, 6), Date.new(2021, 10, 7)]
    assert_equal recurrence_model.events(
      starts: '2021-10-04',
      until: '2021-10-10'
    ), [Date.new(2021, 10, 4), Date.new(2021, 10, 5), Date.new(2021, 10, 6), Date.new(2021, 10, 7)]
  end

  # will fail, date2 = date1, using events!
  test 'events with start_date, end_date as actual end_date (using events!)' do
    recurrence_model = recurrence

    assert_equal recurrence_model.events!(
      starts: '2021-10-04',
      until: '2021-10-10'
    ), [Date.new(2021, 10, 4), Date.new(2021, 10, 5), Date.new(2021, 10, 6), Date.new(2021, 10, 7)]
    assert_equal recurrence_model.events!(
      starts: '2021-10-04',
      until: '2021-10-10'
    ), [Date.new(2021, 10, 4), Date.new(2021, 10, 5), Date.new(2021, 10, 6), Date.new(2021, 10, 7)]
  end

  # will fail, date2 > date1
  test 'events with start_date, end_date outside end_date' do
    recurrence_model = recurrence

    assert_equal recurrence_model.events(
      starts: '2021-09-30',
      until: '2021-10-15'
    ), [Date.new(2021, 10, 4), Date.new(2021, 10, 5), Date.new(2021, 10, 6), Date.new(2021, 10, 7)]
    assert_equal recurrence_model.events(
      starts: '2021-09-30',
      until: '2021-10-15'
    ), [Date.new(2021, 10, 4), Date.new(2021, 10, 5), Date.new(2021, 10, 6), Date.new(2021, 10, 7)]
  end

  # will fail, date2 > date1, using events!
  test 'events with start_date, end_date outside end_date (using events!)' do
    recurrence_model = recurrence

    assert_equal recurrence_model.events!(
      starts: '2021-09-30',
      until: '2021-10-15'
    ), [Date.new(2021, 10, 4), Date.new(2021, 10, 5), Date.new(2021, 10, 6), Date.new(2021, 10, 7)]
    assert_equal recurrence_model.events!(
      starts: '2021-09-30',
      until: '2021-10-15'
    ), [Date.new(2021, 10, 4), Date.new(2021, 10, 5), Date.new(2021, 10, 6), Date.new(2021, 10, 7)]
  end
end

Version: 1.3.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant