Class: DateSet

Inherits:
Object
  • Object
show all
Defined in:
lib/rtmapi.rb

Overview

DateSet is to manage rrules this comes from the iCal ruby module as mentioned here: www.macdevcenter.com/pub/a/mac/2003/09/03/rubycocoa.html

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(startDate, rule) ⇒ DateSet

Returns a new instance of DateSet.



498
499
500
501
502
503
504
505
506
507
508
509
510
# File 'lib/rtmapi.rb', line 498

def initialize(startDate, rule)
    @startDate = startDate
    @frequency = nil
    @count = nil
    @untilDate = nil
    @byMonth = nil
    @byDay = nil
    @starts = nil
    if not rule.nil? then
      @starts = rule.every == 1 ? 'every' : 'after'
      parseRecurrenceRule(rule.rule)
    end
end

Instance Attribute Details

#frequencyObject (readonly)

Returns the value of attribute frequency.



589
590
591
# File 'lib/rtmapi.rb', line 589

def frequency
  @frequency
end

#startDateObject

Returns the value of attribute startDate.



590
591
592
# File 'lib/rtmapi.rb', line 590

def startDate
  @startDate
end

Instance Method Details

#includes?(date) ⇒ Boolean

Returns:

  • (Boolean)


546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
# File 'lib/rtmapi.rb', line 546

def includes?(date)
    return true if date == @startDate
    return false if @untilDate and date > @untilDate
    
    case @frequency
        when 'DAILY'
            #if @untilDate then
            #   return (@startDate..@untilDate).include?(date)
            #end
            increment = @interval ? @interval : 1
            d = @startDate
            counter = 0
            until d > date
                
                if @count then
                    counter += 1
                    if counter >= @count
                        return false
                    end
                end

                d += (increment * SECONDS_PER_DAY)
                if  d.day == date.day and 
                    d.year == date.year and 
                    d.month == date.month then
                    puts "true for start: #{@startDate}, until: #{@untilDate}"
                    return true
                end

            end
            
        when 'WEEKLY'
            return true if @startDate.wday == date.wday
            
        when 'MONTHLY'
            
        when 'YEARLY'

    end
    
    false
end

#parseRecurrenceRule(rule) ⇒ Object



512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
# File 'lib/rtmapi.rb', line 512

def parseRecurrenceRule(rule)
  
    if rule =~ /FREQ=(.*?);/ then
        @frequency = $1
    end
    
    if rule =~ /COUNT=(\d*)/ then
        @count = $1.to_i
    end
    
    if rule =~ /UNTIL=(.*?)[;\r]/ then
        @untilDate = DateParser.parse($1)
    end
    
    if rule =~ /INTERVAL=(\d*)/ then
        @interval = $1.to_i
    end

    if rule =~ /BYMONTH=(.*?);/ then
        @byMonth = $1
    end

    if rule =~ /BYDAY=(.*?);/ then
        @byDay = $1
        #puts "byDay = #{@byDay}"
    end
end

#to_sObject



540
541
542
543
544
# File 'lib/rtmapi.rb', line 540

def to_s
  # after/every  FREQ
     puts "UNIMPLETEMENT"
#        puts "#<DateSet: starts: #{@startDate.strftime("%m/%d/%Y")}, occurs: #{@frequency}, count: #{@count}, until: #{@untilDate}, byMonth: #{@byMonth}, byDay: #{@byDay}>"
end