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
34
35
36
37
38
39
40
41
42
# 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} if Time.new.zone == "EST"

  zones = {"eastern" => -4,
           "central" => -5,
           "mountain" => -6,
           "arizona" => -6,
           "pacific" => -7,
           "alaska" => -8,
           "aleutian" => -9,
           "hawaiian" => -10} if Time.new.zone == "EDT"
  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



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

def to_UTC
  begin
    shift_to_UTC = 5 if Time.new.zone == "EST"
    shift_to_UTC = 4 if Time.new.zone == "EDT"
    self.to_datetime.advance(:hours => shift_to_UTC).to_datetime
  rescue Exception => e
    puts "Unrecognizeable timezone: #{e}"
  end
end