Class: Barometer::Data::ZoneCode
- Inherits:
-
Object
- Object
- Barometer::Data::ZoneCode
- Defined in:
- lib/barometer/data/zone.rb
Class Method Summary collapse
Instance Method Summary collapse
- #code ⇒ Object
-
#initialize(zone, time_class = ::Time) ⇒ ZoneCode
constructor
A new instance of ZoneCode.
- #local_to_utc(local_time) ⇒ Object
- #now ⇒ Object
- #offset ⇒ Object
- #to_s ⇒ Object
- #utc_to_local(utc_time) ⇒ Object
Constructor Details
#initialize(zone, time_class = ::Time) ⇒ ZoneCode
Returns a new instance of ZoneCode.
104 105 106 107 |
# File 'lib/barometer/data/zone.rb', line 104 def initialize(zone, time_class=::Time) @zone = zone @time_class = time_class end |
Class Method Details
.detect?(zone) ⇒ Boolean
100 101 102 |
# File 'lib/barometer/data/zone.rb', line 100 def self.detect?(zone) zone.respond_to?(:to_s) && Utils::ZoneCodeLookup.exists?(zone.to_s) end |
Instance Method Details
#code ⇒ Object
109 110 111 |
# File 'lib/barometer/data/zone.rb', line 109 def code zone end |
#local_to_utc(local_time) ⇒ Object
125 126 127 |
# File 'lib/barometer/data/zone.rb', line 125 def local_to_utc(local_time) local_time - offset end |
#now ⇒ Object
117 118 119 |
# File 'lib/barometer/data/zone.rb', line 117 def now time_class.now.utc + offset end |
#offset ⇒ Object
113 114 115 |
# File 'lib/barometer/data/zone.rb', line 113 def offset Utils::ZoneCodeLookup.offset(zone) end |
#to_s ⇒ Object
121 122 123 |
# File 'lib/barometer/data/zone.rb', line 121 def to_s zone end |
#utc_to_local(utc_time) ⇒ Object
129 130 131 |
# File 'lib/barometer/data/zone.rb', line 129 def utc_to_local(utc_time) utc_time + offset end |