File: tzid_access.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,661 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
module RiCal
  module CoreExtensions #:nodoc:
    module Time #:nodoc:
      #- ©2009 Rick DeNatale
      #- All rights reserved. Refer to the file README.txt for the license
      #
      # Provides a tzid attribute for ::Time and ::DateTime
      module TzidAccess
        # The tzid attribute is used by RiCal, it should be a valid timezone identifier within a calendar,
        # :floating to indicate a floating time, or nil to use the default timezone in effect
        #
        # See PropertyValue::DateTime#default_tzid= and Component::Calendar#tzid=
        attr_accessor :tzid

        # Convenience method, sets the tzid and returns the receiver
        def set_tzid(time_zone_identifier)
          self.tzid = time_zone_identifier
          self
        end

        # Predicate indicating whether or not the instance represents a floating time
        def has_floating_timezone?
          tzid == :floating
        end

      end
    end
  end

  module TimeWithZoneExtension #:nodoc:
    def tzid
      utc? ? "UTC" : time_zone.tzinfo.identifier
    end

    # Predicate indicating whether or not the instance represents a floating time
    def has_floating_timezone?
      false
    end

    def to_ri_cal_date_time_value(timezone_finder=nil)
      ::RiCal::PropertyValue::DateTime.new(timezone_finder, :params => {"TZID" => tzid}, :value => strftime("%Y%m%dT%H%M%S"))
    end
    alias_method :to_ri_cal_date_or_date_time_value, :to_ri_cal_date_time_value
    alias_method :to_ri_cal_occurrence_list_value, :to_ri_cal_date_time_value
  end
end

if RiCal::TimeWithZone
  RiCal::TimeWithZone.class_eval {include RiCal::TimeWithZoneExtension}
end