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

REMonth negative range enhancement request #9

Open
salex opened this issue Jul 29, 2013 · 0 comments
Open

REMonth negative range enhancement request #9

salex opened this issue Jul 29, 2013 · 0 comments

Comments

@salex
Copy link

salex commented Jul 29, 2013

I discovered Runt this week while trying to implement an iCalender type recurring event in a Rails application. I see were the icalendar tests where included, but many test would not work because of lack support for negative mday range.

I'm not very proficient in Ruby, but I attacked the problem by overwriting the REMonth include? method to support negative ranges (which you accept, but don't work)

module Runt    
  class REMonth
    include TExprUtils

    def include?(date)
      if @range.begin < 0 || @range.end < 0
        include_negative(date)
      else
        @range.include? date.mday
      end
    end

    def include_negative(date)
      eom_mday = max_day_of_month(date)
      range = (@range.begin < 0 ? eom_mday + @range.begin + 1 : @range.begin)..(@range.end < 0 ? eom_mday + @range.end + 1 : @range.end)
      range.include? date.mday
    end
  end
end

I couldn't get the tests to run (didn't clone Runt), but this patch seems to work.

# from icalendar test 18

start_date = DateTime.parse("US-Eastern:19970930T090000") #Sep 30, 1997
end_date   = start_date + 365 #Sep 30, 1998
test_date = DateTime.parse("US-Eastern:19971031T090000") #Oct 31
#rrule = RecurrenceRule.new("FREQ=MONTHLY;COUNT=10;BYMONTHDAY=1,-1")
te = REMonth.new(1) | REMonth.new(-1) #first and last days of the month
results = te.dates(DateRange.new(start_date, end_date), 10)

I did notice that if I used Time instead of DateTime and got an error:

results = te.dates(DateRange.new(start_date, end_date), 10)
TypeError: can't iterate from Time

I just have to watch that when I actually try to do something.

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