Changeset 4494
- Timestamp:
- 06/25/06 18:04:06 (2 years ago)
- Files:
-
- trunk/activerecord/CHANGELOG (modified) (1 diff)
- trunk/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb (modified) (4 diffs)
- trunk/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb (modified) (2 diffs)
- trunk/activerecord/test/base_test.rb (modified) (1 diff)
- trunk/activerecord/test/fixtures/topics.yml (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/activerecord/CHANGELOG
r4493 r4494 1 1 *SVN* 2 3 * PostgreSQL: support microsecond time resolution. #5492 [alex@msgpad.com] 2 4 3 5 * 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'1 require 'date' 2 2 3 3 module ActiveRecord … … 110 110 def self.string_to_time(string) 111 111 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) 113 115 # treat 0000-00-00 00:00:00 as nil 114 116 Time.send(Base.default_timezone, *time_array) rescue nil … … 118 120 return string unless string.is_a?(String) 119 121 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) 121 124 # 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) 123 127 Time.send(Base.default_timezone, *time_array) rescue nil 124 128 end … … 133 137 end 134 138 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 136 146 def extract_limit(sql_type) 137 147 return unless sql_type trunk/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
r4460 r4494 123 123 def quote_column_name(name) 124 124 %("#{name}") 125 end 126 127 def quoted_date(value) 128 value.strftime("%Y-%m-%d %H:%M:%S.#{value.usec}") 125 129 end 126 130 … … 527 531 return value unless value.class == DateTime 528 532 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] 530 534 Time.send(Base.default_timezone, *time_array) rescue nil 531 535 end trunk/activerecord/test/base_test.rb
r4459 r4494 316 316 "The written_on attribute should be of the Time class" 317 317 ) 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 318 324 end 319 325 trunk/activerecord/test/fixtures/topics.yml
r4413 r4494 4 4 author_name: David 5 5 author_email_address: david@loudthinking.com 6 written_on: 2003-07-16t15:28: 00.00+01:006 written_on: 2003-07-16t15:28:11.2233+01:00 7 7 last_read: 2004-04-15 8 8 bonus_time: 2005-01-30t15:28:00.00+01:00