Module: Jetlag::TimezoneAwareColumnQuoting

Defined in:
lib/jetlag.rb

Instance Method Summary collapse

Instance Method Details

#quoted_date(value) ⇒ Object

calling #getutc or #getlocal on a TimeWithZone will return the underlying Time. This is desirable because Time#to_s(:db) does not convert to UTC first, unlike TimeWithZone. The same methods on a Time only change the timezone.

This method is backported from Rails 3.



17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/jetlag.rb', line 17

def quoted_date(value)
  if ::Jetlag.enabled?
    if value.acts_like?(:time)
      zone_conversion_method = ActiveRecord::Base.default_timezone == :utc ? :getutc : :getlocal
      value.respond_to?(zone_conversion_method) ? value.send(zone_conversion_method) : value
    else
      value
    end.to_s(:db)
  else
    value.to_s(:db)
  end
end