Class: Icalendar::Timezone
- Defined in:
- lib/icalendar/timezone.rb
Defined Under Namespace
Modules: TzProperties Classes: Daylight, Standard
Instance Attribute Summary
Attributes inherited from Component
Instance Method Summary collapse
- #daylight_for(local) ⇒ Object
-
#initialize ⇒ Timezone
constructor
A new instance of Timezone.
- #offset_for_local(local) ⇒ Object
- #standard_for(local) ⇒ Object
- #valid?(strict = false) ⇒ Boolean
Methods inherited from Component
Methods included from HasComponents
#add_component, #add_custom_component, #custom_component, included, #method_missing, #respond_to_missing?
Methods included from HasProperties
#append_custom_property, #custom_property, included, #method_missing, #property, #respond_to_missing?
Constructor Details
#initialize ⇒ Timezone
Returns a new instance of Timezone.
75 76 77 |
# File 'lib/icalendar/timezone.rb', line 75 def initialize super 'timezone' end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Icalendar::HasComponents
Instance Method Details
#daylight_for(local) ⇒ Object
114 115 116 117 118 119 |
# File 'lib/icalendar/timezone.rb', line 114 def daylight_for(local) possible = daylights.map do |day| [day.previous_occurrence(local.to_time), day] end possible.sort_by(&:first).last end |
#offset_for_local(local) ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/icalendar/timezone.rb', line 86 def offset_for_local(local) standard = standard_for local daylight = daylight_for local if standard.nil? && daylight.nil? "+00:00" elsif daylight.nil? standard.last.tzoffsetto elsif standard.nil? daylight.last.tzoffsetto else sdst = standard.first ddst = daylight.first if sdst > ddst standard.last.tzoffsetto else daylight.last.tzoffsetto end end end |
#standard_for(local) ⇒ Object
107 108 109 110 111 112 |
# File 'lib/icalendar/timezone.rb', line 107 def standard_for(local) possible = standards.map do |std| [std.previous_occurrence(local.to_time), std] end possible.sort_by(&:first).last end |
#valid?(strict = false) ⇒ Boolean
79 80 81 82 83 84 |
# File 'lib/icalendar/timezone.rb', line 79 def valid?(strict = false) daylights.empty? && standards.empty? and return false daylights.all? { |d| d.valid? strict } or return false standards.all? { |s| s.valid? strict } or return false super end |