Class: Barometer::Data::ZoneFull

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) ⇒ ZoneFull

Returns a new instance of ZoneFull.



26
27
28
29
30
# File 'lib/barometer/data/zone.rb', line 26

def initialize(zone, time_class=::Time)
  @zone = zone
  @time_class = time_class
  @tz = TZInfo::Timezone.get(zone)
end

Class Method Details

.detect?(zone) ⇒ Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/barometer/data/zone.rb', line 22

def self.detect?(zone)
  zone.respond_to?(:match) && !!zone.match(/^[A-Za-z]+\/[A-Za-z_]+$/)
end

Instance Method Details

#codeObject



32
33
34
# File 'lib/barometer/data/zone.rb', line 32

def code
  tz.period_for_utc(time_class.now.utc).zone_identifier.to_s
end

#local_to_utc(local_time) ⇒ Object



48
49
50
# File 'lib/barometer/data/zone.rb', line 48

def local_to_utc(local_time)
  tz.local_to_utc(local_time)
end

#nowObject



40
41
42
# File 'lib/barometer/data/zone.rb', line 40

def now
  tz.utc_to_local(time_class.now.utc)
end

#offsetObject



36
37
38
# File 'lib/barometer/data/zone.rb', line 36

def offset
  tz.period_for_utc(time_class.now.utc).utc_total_offset
end

#to_sObject



44
45
46
# File 'lib/barometer/data/zone.rb', line 44

def to_s
  zone
end

#utc_to_local(utc_time) ⇒ Object



52
53
54
# File 'lib/barometer/data/zone.rb', line 52

def utc_to_local(utc_time)
  tz.utc_to_local(utc_time)
end