mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Revert "Fix #microseconds conversion and #fast_string_to_time"
This reverts commit 717a2941e1
. Bunch of failures when running postgresql tests.
This commit is contained in:
parent
cd90dcb1bd
commit
0ab30637dd
2 changed files with 6 additions and 50 deletions
|
@ -13,7 +13,6 @@ module ActiveRecord
|
|||
module Format
|
||||
ISO_DATE = /\A(\d{4})-(\d\d)-(\d\d)\z/
|
||||
ISO_DATETIME = /\A(\d{4})-(\d\d)-(\d\d) (\d\d):(\d\d):(\d\d)(\.\d+)?\z/
|
||||
NEW_ISO_DATETIME = /\A(\d{4})-(\d\d)-(\d\d) (\d\d):(\d\d):(\d\d)(?:\.(\d+))?\z/
|
||||
end
|
||||
|
||||
attr_reader :name, :default, :type, :limit, :null, :sql_type, :precision, :scale
|
||||
|
@ -168,11 +167,10 @@ module ActiveRecord
|
|||
end
|
||||
|
||||
protected
|
||||
# Rational(123456, 1_000_000) -> 123456
|
||||
# The sec_fraction component returned by Date._parse is a Rational fraction of a second or nil
|
||||
# NB: This method is optimized for performance by immediately converting away from Rational.
|
||||
# '0.123456' -> 123456
|
||||
# '1.123456' -> 123456
|
||||
def microseconds(time)
|
||||
((time[:sec_fraction].to_f % 1) * 1_000_000).round
|
||||
((time[:sec_fraction].to_f % 1) * 1_000_000).to_i
|
||||
end
|
||||
|
||||
def new_date(year, mon, mday)
|
||||
|
@ -196,8 +194,9 @@ module ActiveRecord
|
|||
|
||||
# Doesn't handle time zones.
|
||||
def fast_string_to_time(string)
|
||||
if md = Format::NEW_ISO_DATETIME.match(string)
|
||||
new_time *md.to_a[1..7].map(&:to_i)
|
||||
if string =~ Format::ISO_DATETIME
|
||||
microsec = ($7.to_f * 1_000_000).to_i
|
||||
new_time $1.to_i, $2.to_i, $3.to_i, $4.to_i, $5.to_i, $6.to_i, microsec
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -1,43 +0,0 @@
|
|||
require "cases/helper"
|
||||
|
||||
class SchemaDefinitionsTest < ActiveRecord::TestCase
|
||||
|
||||
REGRESSION_SAMPLES = %w{000249 125014 003912 256051 524287}
|
||||
|
||||
test 'fast_string_to_time converts properly' do
|
||||
converted = ActiveRecord::ConnectionAdapters::Column.send('fast_string_to_time', "2010-01-12 12:34:56.000249")
|
||||
assert_equal Time.mktime(2010, 01, 12, 12, 34, 56, 249), converted
|
||||
end
|
||||
|
||||
test 'fallback_string_to_time converts properly' do
|
||||
converted = ActiveRecord::ConnectionAdapters::Column.send('fallback_string_to_time', "2010-01-12 12:34:56.000249")
|
||||
assert_equal Time.mktime(2010, 01, 12, 12, 34, 56, 249), converted
|
||||
end
|
||||
|
||||
test 'fallback_string_to_time converts properly with no microseconds' do
|
||||
converted = ActiveRecord::ConnectionAdapters::Column.send('fallback_string_to_time', "2010-01-12 12:34:56")
|
||||
assert_equal Time.mktime(2010, 01, 12, 12, 34, 56, 0), converted
|
||||
end
|
||||
|
||||
test "fast_string_to_time can handle problematic microseconds" do
|
||||
REGRESSION_SAMPLES.each do |u|
|
||||
converted = ActiveRecord::ConnectionAdapters::Column.send('fast_string_to_time', "2010-01-12 12:34:56.#{u}")
|
||||
assert_equal u.to_i, converted.usec
|
||||
end
|
||||
end
|
||||
|
||||
test "microseconds can handle problematic microseconds" do
|
||||
REGRESSION_SAMPLES.each do |u|
|
||||
i = u.to_i
|
||||
converted = ActiveRecord::ConnectionAdapters::Column.send('microseconds', {:sec_fraction => Rational(i, 1_000_000)})
|
||||
assert_equal i, converted
|
||||
|
||||
converted = ActiveRecord::ConnectionAdapters::Column.send('microseconds', {:sec_fraction => Rational(i, 1_000_000)})
|
||||
assert_equal i, converted
|
||||
end
|
||||
end
|
||||
|
||||
test 'fast constant is equally restrictive' do
|
||||
assert_match ActiveRecord::ConnectionAdapters::Column::Format::NEW_ISO_DATETIME, "2010-01-12 12:34:56.555493"
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue