Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #5517: different_timezone_queries.diff

File different_timezone_queries.diff, 1.7 kB (added by alex@msgpad.com, 2 years ago)

Patch to handle case when Time object timezone != DB's timezone.

  • test/base_test.rb

    old new  
    560560    return true if current_adapter?(:SQLServerAdapter) || current_adapter?(:OracleAdapter) 
    561561 
    562562    Topic.default_timezone = :utc 
     563 
    563564    attributes = { "bonus_time" => "5:42:00AM" } 
    564565    topic = Topic.find(1) 
    565566    topic.attributes = attributes 
    566567    assert_equal Time.utc(2000, 1, 1, 5, 42, 0), topic.bonus_time 
     568 
     569    topic = Topic.find(1) 
     570    time = Time.at(946765680) 
     571    assert_equal topic.id, Topic.find_first(["bonus_time = ?", time]).id 
     572 
    567573    Topic.default_timezone = :local 
    568574  end 
    569575 
  • lib/active_record/connection_adapters/abstract/quoting.rb

    old new  
    4747      end 
    4848       
    4949      def quoted_date(value) 
    50         value.strftime("%Y-%m-%d %H:%M:%S") 
     50        date = value.send("get#{Base.default_timezone}".intern) 
     51        date.strftime("%Y-%m-%d %H:%M:%S.#{date.usec}") 
    5152      end 
    5253    end 
    5354  end 
  • lib/active_record/connection_adapters/postgresql_adapter.rb

    old new  
    125125      end 
    126126 
    127127      def quoted_date(value) 
    128         value.strftime("%Y-%m-%d %H:%M:%S.#{value.usec}") 
     128        date = value.send("get#{Base.default_timezone}".intern) 
     129        date.strftime("%Y-%m-%d %H:%M:%S.#{date.usec}") 
    129130      end 
    130131 
    131132