Quoting cosmin at speakeasy.net, on Sat, May 20, 2006 at 11:40:06AM -0700:> I did some changes to the rrule.rb. I needed some getters/setters for > each of the attributes from RRULE. Attached is the diff. If it makes > sense to you to be included in the lib, please do so. If you think > it''s worth to be included, I can add more validation to the setters.I confess to not really liking it, but I''ll include it because I don''t have time for anything better. Partly, I don''t understand what its for. You have an Rrule, and you want to change it on the fly? Whats the use-case? I want to make an Rrule maker that would hopefully make it easy to build rrules programatically. I''m impressed by the flexibility and power of apples'' iCal gui for building recurrent events, and basically wanted to reuse the model. It can''t do everything, but it can do lots.> I would be interested in testing the RDATE change if you already > implemented it... If not, I"ll try to dig into the code. Can you > please point me what/where needs to be changed?Here is a fast hack, note that it only works with one RDATE field, but multiple are allowed! ensemble:~/p/ruby/vpim/trunk % svn diff lib/vpim/property/recurrence.rb Index: lib/vpim/property/recurrence.rb ==================================================================--- lib/vpim/property/recurrence.rb (revision 360) +++ lib/vpim/property/recurrence.rb (working copy) @@ -39,6 +39,10 @@ occurences.each_until(t1).detect { |t| tend = t + (duration || 0); tend > t0 } end + def rdates + Vpim.decode_date_time_list(propvalue(''RDATE'')) + end + end end end Better would be an Rdate class with the same interfaces as Rrule, and none of the complexity, RDATE is just a list of date or date-time. See propvalueall(). Even better would be a reimplementation of occurrences that creates one Rrule for every RRULE and for every EXRRULE, one Rdate for every RDATE and EXRDATE, and uses ruby generators to return an enumerable class (Occurrences?) that combines correctly all the occurrences. I did a proof-of-concept a few days that takes multiple sorted sequences (Rrule and Rdate would be this) and combines them. Looks pretty straightforward, actually, if you''d like to take a crack at it. See example code below, I think Union as-is would unify multiple Rrule instances as a single enumerable. Btw, I got date and date-time values correctly returned as Date and Time, but I still have to fix some things to get the unit tests working. I haven''t forgotten, its just going slowly. Cheers, Sam require ''generator'' class Union include Enumerable def initialize(*args) @args = args; end def each generators = {} @args.each do |a| g = Generator.new(a) if g.next? generators[g] = g.next end end current = nil while generators.size > 0 current = generators.values.min yield current collect = generators.select{ |k,v| v == current } collect.each do |g,v| if g.next? generators[g] = g.next else generators.delete(g) end end end end end require ''pp'' pp Union.new([1,2,3], [2,3,4]).to_a pp Union.new([1,3], [3,4,5,6]).to_a class Seq def initialize(multiplier) @multiplier = multiplier @start = 1 end def each start = @start loop do yield start start *= @multiplier end end include Enumerable end s3 = Seq.new(3) s4 = Seq.new(4) union = Union.new(s3, s4) union.each do |v| break if v > 100 puts v end
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML><HEAD> <STYLE type=text/css> P, UL, OL, DL, DIR, MENU, PRE { margin: 0 auto;}</STYLE> <META content="MSHTML 6.00.2900.2873" name=GENERATOR></HEAD> <BODY leftMargin=1 topMargin=1 rightMargin=1><FONT face=Tahoma size=2> <DIV>Hi Sam,</DIV> <DIV> </DIV> <DIV>Sorry for the late reply..I got caught up with other things and I didn''t have the time to look over this.</DIV> <DIV> </DIV> <DIV>>> I confess to not really liking it, but I''ll include it because I don''t<BR>>> have time for anything better.<BR></DIV> <DIV>No need to include it then. <BR></DIV> <DIV>>> Partly, I don''t understand what its for. You have an Rrule, and you want<BR>>> to change it on the fly? Whats the use-case?<BR><BR>>> I want to make an Rrule maker that would hopefully make it easy to build<BR>>> rrules programatically. I''m impressed by the flexibility and power of<BR>>> apples'' iCal gui for building recurrent events, and basically wanted to<BR>>> reuse the model. It can''t do everything, but it can do lots.<BR></DIV> <DIV>That was the reason I added my methods (to be able to build programmatically rrules). I guess a Maker will be a better choice, but for me it was a quick solution how I did it, plus I wasn''t that familiar with the library. If I''ll have the time I can look into rewriting it and using a maker for this.</DIV> <DIV><BR><BR>>> Better would be an Rdate class with the same interfaces as Rrule, and none<BR>>> of<BR>>> the complexity, RDATE is just a list of date or date-time. See<BR>>> propvalueall().<BR></DIV> <DIV>I implemented it like this. A different class but with a similar interface with Rrule. I also changed a bit the occurrences method so it will read the rdates too. I can send you the code if you think it''s worth it.</DIV> <DIV> </DIV> <DIV><BR>>> Even better would be a reimplementation of occurrences that creates one<BR>>> Rrule<BR>>> for every RRULE and for every EXRRULE, one Rdate for every RDATE and<BR>>> EXRDATE,<BR>>> and uses ruby generators to return an enumerable class (Occurrences?) that<BR>>> combines correctly all the occurrences.<BR></DIV> <DIV>This is a bit wrong actually as the EXRULEs and EXRDATEs need to be excluded out of the list of occurrences.</DIV> <DIV>Your Union class looks good though... :) I guess the easiest way to do this is to generate a union out of RRULEs and RDATEs and then exclude the instances that are in a second union which was created from EXRRULE and EXRDATE.</DIV> <DIV> </DIV> <DIV>The code that I have (and I can e-mail it to you if you want to review it) is for generating recurrence sets with RRULE and/or RDATE (I assumed only 1 instance of each property max.. I know that in the standard it says it could be more than one, but I never seen anyone using it).</DIV> <DIV> </DIV> <DIV>Bye,</DIV> <DIV>Cosmin</DIV></FONT></BODY></HTML>
Quoting cosmin at speakeasy.net, on Sun, Jun 04, 2006 at 04:20:12PM -0700:> >> I confess to not really liking it, but I''ll include it because I > don''t > >> have time for anything better. > > No need to include it then.It will help others if it helps you, and I don''t have time to work on this. I should send you my patch to make DTSTART and friends return a Date if the value is a DATE. I''ve no time to finish it, but it might work well-enough for you.> >> Better would be an Rdate class with the same interfaces as Rrule, > and none > >> of > >> the complexity, RDATE is just a list of date or date-time. See > >> propvalueall(). > > I implemented it like this. A different class but with a similar > interface with Rrule. I also changed a bit the occurrences method so > it will read the rdates too. I can send you the code if you think it''s > worth it.Please do.> >> Even better would be a reimplementation of occurrences that > creates one > >> Rrule > >> for every RRULE and for every EXRRULE, one Rdate for every RDATE > and > >> EXRDATE, > >> and uses ruby generators to return an enumerable class > (Occurrences?) that > >> combines correctly all the occurrences. > > This is a bit wrong actually as the EXRULEs and EXRDATEs need to be > excluded out of the list of occurrences.Absolutely, by "correctly" I meant add the ones that need adding, and remove the ones that need removing.> Your Union class looks good though... :) I guess the easiest way to > do this is to generate a union out of RRULEs and RDATEs and then > exclude the instances that are in a second union which was created > from EXRRULE and EXRDATE.I think what would be needed would be a version of Union that does Rejection... rrule1 rdate1 rrule2 exdate3 exrule4 occurences = Rejection.new( Union.new(rrule1,rdate1,rrule2), Union.new(exdate3,exrule4) )> The code that I have (and I can e-mail it to you if you want to review > it) is for generating recurrence sets with RRULE and/or RDATE (I > assumed only 1 instance of each property max.. I know that in the > standard it says it could be more than one, but I never seen anyone > using it).I can''t find the time to work on vPim lately. I will try and get the DATE patch I started to you, so you can see where it is going and maybe finish it? It works, just some unit tests are failing (because they have been generating invalid calendar files). Sam