From jos at teamonline.dk Thu May 14 05:07:40 2009 From: jos at teamonline.dk (Joe =?ISO-8859-1?Q?S=F8rensen?=) Date: Thu, 14 May 2009 11:07:40 +0200 Subject: [iCalendar-devel] Bug in RRule class Message-ID: <1242292060.8163.37.camel@joe-desktop> Dear sir, I have found a bug in the RRule class. This example will explain the problem: >> weekend = RRule.new( nil, nil, "FREQ=WEEKLY;BYDAY=SA,SU", nil ).to_ical => "FREQ=WEEKLY;BYDAY=SASU" As you can see, the ',' was removed between 'SA' and 'SU'. I have tried to fix this the bedst i can. As I didn't know howto issue bugs in this project or patches, I have decided to append my patch to this mail. The following patch corrects this but for me. You can include it or fix the problem in any other way. I couldn't figure out what the @position in the Weekday class is for, so I removed it from the output, but didn't remove it completely. Index: plugins/icalendar-1.1.0/lib/icalendar/parser.rb =================================================================== --- plugins/icalendar-1.1.0/lib/icalendar/parser.rb (revision 5040) +++ plugins/icalendar-1.1.0/lib/icalendar/parser.rb (working copy) @@ -17,11 +17,16 @@ class Weekday def initialize(day, position) @day, @position = day, position + @last = false end def to_s - "#{@position}#{@day}" + "#{@day}#{ "," unless @last }" end + + def you_are_last() + @last = true + end end def initialize(name, params, value, parser) @@ -78,15 +83,17 @@ def parse_weekday_list(name, string) match = string.match(/;#{name}=(.*?)(;|$)/) if match - match[1].split(",").map {|weekday| + return_array = match[1].split(",").map {|weekday| wd_match = weekday.match(/([+-]?\d*)(SU|MO|TU|WE|TH|FR|SA)/) Weekday.new(wd_match[2], wd_match[1]) } + return_array.last.you_are_last else nil end + return_array end - + def parse_wkstart(string) match = string.match(/;WKSTART=(SU|MO|TU|WE|TH|FR|SA)(;|$)/) if match From jos at teamonline.dk Thu May 14 05:36:51 2009 From: jos at teamonline.dk (Joe =?ISO-8859-1?Q?S=F8rensen?=) Date: Thu, 14 May 2009 11:36:51 +0200 Subject: [iCalendar-devel] Bug in RRule class In-Reply-To: <1242292060.8163.37.camel@joe-desktop> References: <1242292060.8163.37.camel@joe-desktop> Message-ID: <1242293811.8163.45.camel@joe-desktop> I guess the @position should be in the output from Weekday. I just learned you can say 2. Sunday in May by: "FREQ=MONTHLY;BYMONTH=5;BYDAY=2SU" I'm surry. My Mistake. Here is a patch for my patch. Index: plugins/icalendar-1.1.0/lib/icalendar/parser.rb =================================================================== --- plugins/icalendar-1.1.0/lib/icalendar/parser.rb (revision 5050) +++ plugins/icalendar-1.1.0/lib/icalendar/parser.rb (working copy) @@ -21,7 +21,7 @@ end def to_s - "#{@day}#{ "," unless @last }" + "#{@position}#{@day}#{ "," unless @last }" end def you_are_last() tor, 14 05 2009 kl. 11:07 +0200, skrev Joe S?rensen: > Dear sir, > > I have found a bug in the RRule class. This example will explain the > problem: > > >> weekend = RRule.new( nil, nil, "FREQ=WEEKLY;BYDAY=SA,SU", > nil ).to_ical > => "FREQ=WEEKLY;BYDAY=SASU" > > As you can see, the ',' was removed between 'SA' and 'SU'. > > I have tried to fix this the bedst i can. > > As I didn't know howto issue bugs in this project or patches, I have > decided to append my patch to this mail. The following patch corrects > this but for me. You can include it or fix the problem in any other way. > I couldn't figure out what the @position in the Weekday class is for, so > I removed it from the output, but didn't remove it completely. > > Index: plugins/icalendar-1.1.0/lib/icalendar/parser.rb > =================================================================== > --- plugins/icalendar-1.1.0/lib/icalendar/parser.rb (revision 5040) > +++ plugins/icalendar-1.1.0/lib/icalendar/parser.rb (working copy) > @@ -17,11 +17,16 @@ > class Weekday > def initialize(day, position) > @day, @position = day, position > + @last = false > end > > def to_s > - "#{@position}#{@day}" > + "#{@day}#{ "," unless @last }" > end > + > + def you_are_last() > + @last = true > + end > end > > def initialize(name, params, value, parser) > @@ -78,15 +83,17 @@ > def parse_weekday_list(name, string) > match = string.match(/;#{name}=(.*?)(;|$)/) > if match > - match[1].split(",").map {|weekday| > + return_array = match[1].split(",").map {|weekday| > wd_match = weekday.match(/([+-]?\d*)(SU|MO|TU|WE|TH|FR|SA)/) > Weekday.new(wd_match[2], wd_match[1]) > } > + return_array.last.you_are_last > else > nil > end > + return_array > end > - > + > def parse_wkstart(string) > match = string.match(/;WKSTART=(SU|MO|TU|WE|TH|FR|SA)(;|$)/) > if match > > > _______________________________________________ > icalendar-devel mailing list > icalendar-devel at rubyforge.org > http://rubyforge.org/mailman/listinfo/icalendar-devel >