Sha256: 56f19ae3d48a68d1fdc81bbad48cfec855a6e7caca11170ebeb6910e3d47a39a

Contents?: true

Size: 1.79 KB

Versions: 8

Compression:

Stored size: 1.79 KB

Contents

require 'date'
module RiCal
  module CoreExtensions #:nodoc:
    module DateTime #:nodoc:
      #- ©2009 Rick DeNatale
      #- All rights reserved. Refer to the file README.txt for the license
      #
      module Conversions #:nodoc:
        # Return an RiCal::PropertyValue::DateTime representing the receiver
        def to_ri_cal_date_time_value(timezone_finder = nil) #:nodoc:
          RiCal::PropertyValue::DateTime.new(
               timezone_finder, 
               :value => strftime("%Y%m%dT%H%M%S"), 
               :params => {"TZID" => self.tzid || :default})
        end

        alias_method :to_ri_cal_date_or_date_time_value, :to_ri_cal_date_time_value #:nodoc:
        alias_method :to_ri_cal_occurrence_list_value, :to_ri_cal_date_time_value #:nodoc:

        # Return the natural ri_cal_property for this object
        def to_ri_cal_property_value(timezone_finder = nil) #:nodoc:
          to_ri_cal_date_time_value(timezone_finder)
        end
        
        def to_overlap_range_start
          self
        end
        alias_method :to_overlap_range_end, :to_overlap_range_start
        
        # Return a copy of this object which will be interpreted as a floating time.
        def with_floating_timezone
          dup.set_tzid(:floating)
        end
        
        unless DateTime.instance_methods.map {|selector| selector.to_sym}.include?(:to_date)
          # Converts self to a Ruby Date object; time portion is discarded
          def to_date
            ::Date.new(year, month, day)
          end
        end
        unless DateTime.instance_methods.map {|selector| selector.to_sym}.include?(:to_datetime)
          # To be able to keep Times, Dates and DateTimes interchangeable on conversions
          def to_datetime
            self
          end
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 5 rubygems

Version Path
demingfactor-ri_cal-0.10.0 lib/ri_cal/core_extensions/date_time/conversions.rb
demingfactor-ri_cal-0.9.0 lib/ri_cal/core_extensions/date_time/conversions.rb
awallis-ri_cal-0.8.8 lib/ri_cal/core_extensions/date_time/conversions.rb
justinsoong-ri_cal-0.8.9 lib/ri_cal/core_extensions/date_time/conversions.rb
justinsoong-ri_cal-0.8.8 lib/ri_cal/core_extensions/date_time/conversions.rb
micahwedemeyer-ri_cal-0.8.10 lib/ri_cal/core_extensions/date_time/conversions.rb
micahwedemeyer-ri_cal-0.8.9 lib/ri_cal/core_extensions/date_time/conversions.rb
ri_cal-0.8.8 lib/ri_cal/core_extensions/date_time/conversions.rb