Class: Barometer::Data::ZoneOffset

Inherits:
Object
  • Object
show all
Defined in:
lib/barometer/data/zone.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(zone, time_class = ::Time) ⇒ ZoneOffset

Returns a new instance of ZoneOffset.



66
67
68
69
# File 'lib/barometer/data/zone.rb', line 66

def initialize(zone, time_class=::Time)
  @zone = zone
  @time_class = time_class
end

Class Method Details

.detect?(zone) ⇒ Boolean

Returns:

  • (Boolean)


62
63
64
# File 'lib/barometer/data/zone.rb', line 62

def self.detect?(zone)
  zone.respond_to?(:abs) && zone.abs <= 14
end

Instance Method Details

#codeObject



71
72
# File 'lib/barometer/data/zone.rb', line 71

def code
end

#local_to_utc(local_time) ⇒ Object



86
87
88
# File 'lib/barometer/data/zone.rb', line 86

def local_to_utc(local_time)
  local_time - offset
end

#nowObject



78
79
80
# File 'lib/barometer/data/zone.rb', line 78

def now
  time_class.now.utc + offset
end

#offsetObject



74
75
76
# File 'lib/barometer/data/zone.rb', line 74

def offset
  zone.to_f * 60 * 60
end

#to_sObject



82
83
84
# File 'lib/barometer/data/zone.rb', line 82

def to_s
  zone.to_s
end

#utc_to_local(utc_time) ⇒ Object



90
91
92
# File 'lib/barometer/data/zone.rb', line 90

def utc_to_local(utc_time)
  utc_time + offset
end