Sha256: 1703e7a7735e9be7db80cebdd6f8200c2ac3d57d79abcb22e7c754c3d268a200

Contents?: true

Size: 1.46 KB

Versions: 1

Compression:

Stored size: 1.46 KB

Contents

module RiCal
  # RequireTimezones collects the timezones used by a given calendar component or set of calendar components
  # For each timezone we collect it's id, and the earliest and latest times which reference the zone
  class RequiredTimezones #:nodoc:
    
    
    # A required timezone represents a single timezone and the earliest and latest times which reference it.
    class RequiredTimezone #:nodoc:
      
      attr_reader :first_time, :last_time, :timezone
      
      def initialize(tzid)
        @timezone = RiCal::Component::TZInfoTimezone.new(TZInfo::Timezone.get(tzid))
      end
      
      def tzid
        @timezone.identifier
      end
      
      def add_datetime(date_time)
        if @first_time 
          @first_time = date_time if date_time < @first_time
        else
          @first_time = date_time
        end
        if @last_time 
          @last_time = date_time if date_time > @last_time
        else
          @last_time = date_time
        end
      end
    end
    
    def required_timezones
      @required_zones ||= {}
    end
    
    def required_zones
      required_timezones.values
    end
    
    def export_to(export_stream)
      required_zones.each do |z|
        tzinfo_timezone =z.timezone
        tzinfo_timezone.export_local_to(export_stream, z.first_time, z.last_time)
      end
    end
    
    def add_datetime(date_time, tzid)
      (required_timezones[tzid] ||= RequiredTimezone.new(tzid)).add_datetime(date_time)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
friflaj_ri_cal-0.9.0 lib/ri_cal/required_timezones.rb