Class: EventStore::TimeHacker

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

Class Method Summary collapse

Class Method Details

.translate_occurred_at_from_local_to_gmt(occurred_at) ⇒ Object

Hack around various DB adapters that hydrate dates from the db into the local ruby timezone



5
6
7
8
9
10
11
12
13
# File 'lib/event_store/time_hacker.rb', line 5

def translate_occurred_at_from_local_to_gmt(occurred_at)
  if occurred_at.class == Time
    #expecting "2001-02-03 01:26:40 -0700"
    Time.parse(occurred_at.to_s.gsub(/\s[+-]\d+$/, ' UTC'))
  elsif occurred_at.class == DateTime
    #expecting "2001-02-03T01:26:40+00:00"
    Time.parse(occurred_at.iso8601.gsub('T', ' ').gsub(/[+-]\d{2}\:\d{2}/, ' UTC'))
  end
end