mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Dates and times interpret empty strings as nil rather than 2000-01-01. Closes #4830.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4327 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
parent
d59f3a78a4
commit
d08d89c092
3 changed files with 29 additions and 1 deletions
|
@ -1,5 +1,7 @@
|
|||
*SVN*
|
||||
|
||||
* Dates and times interpret empty strings as nil rather than 2000-01-01. #4830 [kajism@yahoo.com]
|
||||
|
||||
* Allow :uniq => true with has_many :through associations. [Jeremy Kemper]
|
||||
|
||||
* Ensure that StringIO is always available for the Schema dumper. [Marcel Molina Jr.]
|
||||
|
|
|
@ -115,6 +115,7 @@ module ActiveRecord
|
|||
|
||||
def self.string_to_dummy_time(string)
|
||||
return string unless string.is_a?(String)
|
||||
return nil if string.empty?
|
||||
time_array = ParseDate.parsedate(string)
|
||||
# pad the resulting array with dummy date information
|
||||
time_array[0] = 2000; time_array[1] = 1; time_array[2] = 1;
|
||||
|
|
25
activerecord/test/empty_date_time_test.rb
Normal file
25
activerecord/test/empty_date_time_test.rb
Normal file
|
@ -0,0 +1,25 @@
|
|||
require 'abstract_unit'
|
||||
require 'fixtures/topic'
|
||||
require 'fixtures/task'
|
||||
|
||||
class EmptyDateTimeTest < Test::Unit::TestCase
|
||||
def test_assign_empty_date_time
|
||||
task = Task.new
|
||||
task.starting = ''
|
||||
task.ending = nil
|
||||
assert_nil task.starting
|
||||
assert_nil task.ending
|
||||
end
|
||||
|
||||
def test_assign_empty_date
|
||||
topic = Topic.new
|
||||
topic.last_read = ''
|
||||
assert_nil topic.last_read
|
||||
end
|
||||
|
||||
def test_assign_empty_time
|
||||
topic = Topic.new
|
||||
topic.bonus_time = ''
|
||||
assert_nil topic.bonus_time
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue