File: conversions.rb

package info (click to toggle)
mhc 1.1.1-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 2,320 kB
  • ctags: 3,529
  • sloc: ruby: 12,404; lisp: 7,448; makefile: 70; sh: 69
file content (50 lines) | stat: -rw-r--r-- 1,832 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
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