square/ruby-rrule

BYWEEKDAY values are not being applied correctly

Closed this issue · 2 comments

It seems that BYWEEKDAY values are not be taken into account, as shown by the pry session below. BYDAY seems to work fine, but I thought BYWEEKDAY was supposed to work here as well.

[1] pry(main)> require 'rrule'
=> true
[2] pry(main)> rule = RRule.parse('BYWEEKDAY=TH;FREQ=WEEKLY;INTERVAL=1')
=> #<RRule::Rule:0x00007fb2c3c46918
 @dtstart=Mon, 19 Jul 2021 17:42:38 UTC +00:00,
 @exdate=[],
 @frequency_type=RRule::SimpleWeekly,
 @max_date=Fri, 01 Jan 9999 00:00:00 +0000,
 @max_year=9999,
 @options={:interval=>1, :wkst=>1, :freq=>"WEEKLY", :simple_weekly=>true, :byweekday=>[#<RRule::Weekday:0x00007fb2c3c45400 @index=1, @ordinal=nil>], :bynweekday=>[], :timeset=>[{:hour=>17, :minute=>42, :second=>38}]},
 @tz="UTC">
[3] pry(main)> rule.all(limit: 1)
=> [Mon, 19 Jul 2021 17:42:38 UTC +00:00]
[4] pry(main)> rule = RRule.parse('BYDAY=TH;FREQ=WEEKLY;INTERVAL=1')
=> #<RRule::Rule:0x00007fb2c3994d78
 @dtstart=Mon, 19 Jul 2021 17:43:08 UTC +00:00,
 @exdate=[],
 @frequency_type=RRule::Weekly,
 @max_date=Fri, 01 Jan 9999 00:00:00 +0000,
 @max_year=9999,
 @options={:interval=>1, :wkst=>1, :byweekday=>[#<RRule::Weekday:0x00007fb2c399fe58 @index=4, @ordinal=nil>], :freq=>"WEEKLY", :bynweekday=>[], :timeset=>[{:hour=>17, :minute=>43, :second=>8}]},
 @tz="UTC">
[5] pry(main)> rule.all(limit: 1)
=> [Thu, 22 Jul 2021 17:43:08 UTC +00:00]
[6] pry(main)>

AFAIK, BYWEEKDAY isn't part of the RRULE spec (although some libraries like Python's rrule use it as a valid constructor argument, presumably because BYDAY is a little ambiguous?). Definitely possible my knowledge is outdated, though - this is the spec I've been going off.

Sorry it took so long to get back to this. I was seeing the BYWEEKDAY values in an application that used an rrule library from another language, and that library used BYWEEKDAY internally. I can just substitute BYDAY for BYWEEKDAY before passing the string to rrule, so I'm gonna close this.