Class: PulseMeter::TimeConverter

Inherits:
Object
  • Object
show all
Defined in:
lib/pulse_meter/time_converter.rb

Instance Method Summary collapse

Constructor Details

#initialize(timezone_name) ⇒ TimeConverter

Returns a new instance of TimeConverter.



5
6
7
8
9
# File 'lib/pulse_meter/time_converter.rb', line 5

def initialize(timezone_name)
  @tz = TZInfo::Timezone.get(timezone_name)
rescue TZInfo::InvalidTimezoneIdentifier
  @tz = TZInfo::Timezone.get('UTC')
end

Instance Method Details

#from_redis(time) ⇒ Object



15
16
17
# File 'lib/pulse_meter/time_converter.rb', line 15

def from_redis(time)
  tz_period.to_utc(time.to_i).to_i
end

#to_redis(time) ⇒ Object



11
12
13
# File 'lib/pulse_meter/time_converter.rb', line 11

def to_redis(time)
  tz_period.to_local(time.to_i).to_i
end