Permalink
Browse files

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
  • Loading branch information...
1 parent d59f3a7 commit d08d89c09285ac6c65273c935a1afbbc983f7544 @jeremy jeremy committed May 7, 2006
View
@@ -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 @@ def self.string_to_time(string)
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;
@@ -175,7 +176,7 @@ def to_sql
private
def type_to_sql(name, limit)
base.type_to_sql(name, limit) rescue name
- end
+ end
def add_column_options!(sql, options)
base.add_column_options!(sql, options.merge(:column => self))
@@ -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

0 comments on commit d08d89c

Please sign in to comment.