Class: Icalendar::Timezone
- Defined in:
- lib/icalendar/timezone.rb
Defined Under Namespace
Modules: TzProperties Classes: Daylight, Standard
Constant Summary
Constants included from HasComponents
HasComponents::METHOD_MISSING_ADD_REGEX, HasComponents::METHOD_MISSING_X_FLAG_REGEX
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.
77 78 79 |
# File 'lib/icalendar/timezone.rb', line 77 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
117 118 119 120 121 122 123 |
# File 'lib/icalendar/timezone.rb', line 117 def daylight_for(local) possible = daylights.map do |day| prev = day.previous_occurrence(local.to_time) [prev, day] unless prev.nil? end.compact possible.sort_by(&:first).last end |
#offset_for_local(local) ⇒ Object
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/icalendar/timezone.rb', line 88 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
109 110 111 112 113 114 115 |
# File 'lib/icalendar/timezone.rb', line 109 def standard_for(local) possible = standards.map do |std| prev = std.previous_occurrence(local.to_time) [prev, std] unless prev.nil? end.compact possible.sort_by(&:first).last end |
#valid?(strict = false) ⇒ Boolean
81 82 83 84 85 86 |
# File 'lib/icalendar/timezone.rb', line 81 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 |