# File lib/vpim/rrule.rb, line 59
    def initialize(dtstart, rrule = nil)
       @dtstart = dtstart.getlocal
       # The getlocal is a hack so that UTC times get converted to local,
       # because yielded times are always local, because we don't support
       # timezones.
       @rrule = rrule

       # Freq is mandatory, but must occur only once.
       @freq = nil
   
       # Both Until and Count must not occur, neither is OK.
       @until = nil
       @count = nil
   
       # Interval is optional, but defaults to 1.
       @interval = 1

       # WKST defines what day a week begins on, the default is monday.
       @wkst = 'MO'
   
       # Recurrence can modified by these.
       @by = {}
  
       if @rrule
         @rrule.scan(/([^;=]+)=([^;=]+)/) do |key,value|
           key.upcase!
           value.upcase!

           case key
           when 'FREQ'
             @freq = value

           when 'UNTIL'
             if @count
               raise "found UNTIL, but COUNT already specified"
             end
             @until = Rrule.time_from_rfc2425(value)

           when 'COUNT'
             if @until
               raise "found COUNT, but UNTIL already specified"
             end
             @count = value.to_i

           when 'INTERVAL'
             @interval = value.to_i
             if @interval < 1
               raise "interval must be a positive integer"
             end

           when 'WKST'
             # TODO - check value is MO-SU
             @wkst = value

           else
             @by[key] = value
           end
         end

         if !@freq
           # TODO - this shouldn't be an arg error, but a FormatError, its not the
           # caller's fault!
           raise ArgumentError, "recurrence rule lacks a frequency"
         end
       end
    end