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

Changeset 271

Show
Ignore:
Timestamp:
12/28/04 17:30:17 (4 years ago)
Author:
david
Message:

Added Base.default_timezone accessor that determines whether to use Time.local (using :local) or Time.utc (using :utc) when pulling dates and times from the database. This is set to :local by default.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/activerecord/CHANGELOG

    r270 r271  
    11*SVN* 
     2 
     3* Added Base.default_timezone accessor that determines whether to use Time.local (using :local) or Time.utc (using :utc) when pulling dates  
     4  and times from the database. This is set to :local by default. 
    25 
    36* Added the possibility for adapters to overwrite add_limit! to implement a different limiting scheme than "LIMIT X" used by MySQL, PostgreSQL, and SQLite. 
  • trunk/activerecord/lib/active_record/base.rb

    r269 r271  
    221221    cattr_accessor :pluralize_table_names 
    222222    @@pluralize_table_names = true 
     223 
     224    # Determines whether to use Time.local (using :local) or Time.utc (using :utc) when pulling dates and times from the database. 
     225    # This is set to :local by default. 
     226    cattr_accessor :default_timezone 
     227    @@default_timezone = :local 
    223228 
    224229    # When turned on (which is default), all associations are included using "load". This mean that any change is instant in cached 
  • trunk/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb

    r269 r271  
    221221          time_array = ParseDate.parsedate(string).compact 
    222222          # treat 0000-00-00 00:00:00 as nil 
    223           Time.local(*time_array) rescue nil 
    224         end 
    225  
    226        def string_to_dummy_time(string) 
    227          return string if Time === string 
    228          time_array = ParseDate.parsedate(string) 
    229          # pad the resulting array with dummy date information 
    230          time_array[0] = 2000; time_array[1] = 1; time_array[2] = 1; 
    231          Time.local(*time_array) rescue nil 
    232        end 
    233  
     223          Time.send(Base.default_timezone, *time_array) rescue nil 
     224        end 
     225 
     226        def string_to_dummy_time(string) 
     227          return string if Time === string 
     228          time_array = ParseDate.parsedate(string) 
     229          # pad the resulting array with dummy date information 
     230          time_array[0] = 2000; time_array[1] = 1; time_array[2] = 1; 
     231          Time.send(Base.default_timezone, *time_array) rescue nil 
     232        end 
     233         
    234234        def extract_limit(sql_type) 
    235235          $1.to_i if sql_type =~ /\((.*)\)/ 
    236236        end 
    237  
     237         
    238238        def simplified_type(field_type) 
    239239          case field_type 
  • trunk/activerecord/test/base_test.rb

    r228 r271  
    328328    assert_nil topic.last_read 
    329329  end 
    330    
     330 
     331  def test_utc_as_time_zone 
     332    Topic.default_timezone = :utc 
     333    attributes = { "bonus_time" => "5:42:00AM" } 
     334    topic = Topic.find(1) 
     335    topic.attributes = attributes 
     336    assert_equal Time.utc(2000, 1, 1, 5, 42, 0), topic.bonus_time 
     337    Topic.default_timezone = :local 
     338  end 
     339 
    331340  def test_default_values_on_empty_strings 
    332341    topic = Topic.new