Sha256: f27d186f71d17dfe278335a753a4dd419b957668e875700caabbde0417709a3a

Contents?: true

Size: 1.94 KB

Versions: 1

Compression:

Stored size: 1.94 KB

Contents

module RiCal
  class Component
    class Timezone
      # A TimezonePeriod is a component of a timezone representing a period during which a particular offset from UTC is
      # in effect.
      #
      # to see the property accessing methods for this class see the RiCal::Properties::TimezonePeriod module
      class TimezonePeriod < Component
        include Properties::TimezonePeriod

        include OccurrenceEnumerator

        def occurrence_cache #:nodoc:
          @occurrence_cache ||= []
        end

        def zone_identifier #:nodoc:
          tzname.first
        end

        def dtend #:nodoc:
          nil
        end

        def exdate_property #:nodoc:
          nil
        end

        def utc_total_offset #:nodoc:
          tzoffsetto_property.to_seconds
        end

        def exrule_property #:nodoc:
          nil
        end

        def last_before_utc(utc_time) #:nodoc:
          last_before_local(utc_time + tzoffsetfrom_property)
        end

        def fill_cache(local_time)
          if occurrence_cache.empty? || occurrence_cache.last.dtstart_property <= local_time
            while true
              occurrence = enumeration_instance.next_occurrence
              break unless occurrence
              occurrence = recurrence(occurrence)
              occurrence_cache << occurrence
              break if occurrence.dtstart_property > local_time
            end
          end
        end

        def last_before_local(local_time) #:nodoc:
          if recurs?
            fill_cache(local_time)
            cand_occurrence = nil
            occurrence_cache.each do |occurrence|
              return cand_occurrence if occurrence.dtstart_property > local_time
              cand_occurrence = occurrence
            end
            return cand_occurrence
          else
            return self
          end
        end

         def enumeration_instance
          @enumeration_instance ||= super
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
friflaj_ri_cal-0.9.0 lib/ri_cal/component/timezone/timezone_period.rb