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

Changeset 4494

Show
Ignore:
Timestamp:
06/25/06 18:04:06 (2 years ago)
Author:
bitsweat
Message:

PostgreSQL: support microsecond time resolution. Closes #5492.

Files:

Legend:

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

    r4493 r4494  
    11*SVN* 
     2 
     3* PostgreSQL: support microsecond time resolution. #5492 [alex@msgpad.com] 
    24 
    35* Add AssociationCollection#sum since the method_missing invokation has been shadowed by Enumerable#sum. 
  • trunk/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb

    r4477 r4494  
    1 require 'parsedate' 
     1require 'date' 
    22 
    33module ActiveRecord 
     
    110110      def self.string_to_time(string) 
    111111        return string unless string.is_a?(String) 
    112         time_array = ParseDate.parsedate(string)[0..5] 
     112        time_hash = Date._parse(string) 
     113        time_hash[:sec_fraction] = microseconds(time_hash) 
     114        time_array = time_hash.values_at(:year, :mon, :mday, :hour, :min, :sec, :sec_fraction) 
    113115        # treat 0000-00-00 00:00:00 as nil 
    114116        Time.send(Base.default_timezone, *time_array) rescue nil 
     
    118120        return string unless string.is_a?(String) 
    119121        return nil if string.empty? 
    120         time_array = ParseDate.parsedate(string) 
     122        time_hash = Date._parse(string) 
     123        time_hash[:sec_fraction] = microseconds(time_hash) 
    121124        # pad the resulting array with dummy date information 
    122         time_array[0] = 2000; time_array[1] = 1; time_array[2] = 1; 
     125        time_array = [2000, 1, 1] 
     126        time_array += time_hash.values_at(:hour, :min, :sec, :sec_fraction) 
    123127        Time.send(Base.default_timezone, *time_array) rescue nil 
    124128      end 
     
    133137      end 
    134138 
    135     private 
     139      private 
     140        # '0.123456' -> 123456 
     141        # '1.123456' -> 123456 
     142        def self.microseconds(time) 
     143          ((time[:sec_fraction].to_f % 1) * 1_000_000).to_i 
     144        end 
     145 
    136146        def extract_limit(sql_type) 
    137147          return unless sql_type 
  • trunk/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb

    r4460 r4494  
    123123      def quote_column_name(name) 
    124124        %("#{name}") 
     125      end 
     126 
     127      def quoted_date(value) 
     128        value.strftime("%Y-%m-%d %H:%M:%S.#{value.usec}") 
    125129      end 
    126130 
     
    527531          return value unless value.class == DateTime 
    528532          v = value 
    529           time_array = [v.year, v.month, v.day, v.hour, v.min, v.sec
     533          time_array = [v.year, v.month, v.day, v.hour, v.min, v.sec, v.usec
    530534          Time.send(Base.default_timezone, *time_array) rescue nil 
    531535        end 
  • trunk/activerecord/test/base_test.rb

    r4459 r4494  
    316316      "The written_on attribute should be of the Time class" 
    317317    ) 
     318 
     319    # For adapters which support microsecond resolution. 
     320    if current_adapter?(:PostgreSQLAdapter) 
     321      assert_equal 11, Topic.find(1).written_on.sec 
     322      assert_equal 223300, Topic.find(1).written_on.usec 
     323    end 
    318324  end 
    319325   
  • trunk/activerecord/test/fixtures/topics.yml

    r4413 r4494  
    44  author_name: David 
    55  author_email_address: david@loudthinking.com 
    6   written_on: 2003-07-16t15:28:00.00+01:00 
     6  written_on: 2003-07-16t15:28:11.2233+01:00 
    77  last_read: 2004-04-15 
    88  bonus_time: 2005-01-30t15:28:00.00+01:00