Class: Time

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

Instance Method Summary collapse

Instance Method Details

#change_timezone(options) ⇒ Object

adjust according to what you want to view



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/hackapp_gem.rb', line 17

def change_timezone(options)
  zones = {"eastern" => -5,
           "central" => -6,
           "mountain" => -7,
           "arizona" => -7,
           "pacific" => -8,
           "alaska" => -9,
           "aleutian" => -10,
           "hawaiian" => -11}
  begin
    end_zone_offset = zones[options[:new_timezone]]
    # to_UTC is called because the times in db are already eastern
    self.to_UTC.to_datetime.advance(:hours => end_zone_offset).to_datetime
  rescue Exception => e
    puts "Unrecognizeable timezone: #{e}"
  end
end

#to_UTCObject

times in database are eastern time to add 5 hours to all



7
8
9
10
11
12
13
14
# File 'lib/hackapp_gem.rb', line 7

def to_UTC
  begin
    shift_to_UTC = 5
    self.to_datetime.advance(:hours => shift_to_UTC).to_datetime
  rescue Exception => e
    puts "Unrecognizeable timezone: #{e}"
  end
end