Permalink
Browse files

Use Date#to_s(:db) for quoted dates. Closes #7411.

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6061 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
1 parent 17fee00 commit c6b15dde1be9f93b77e9e33ee981124a1a49c6f8 @jeremy jeremy committed Jan 28, 2007
@@ -1,5 +1,7 @@
*SVN*
+* Use Date#to_s(:db) for quoted dates. #7411 [Michael Schoen]
+
* Don't create instance writer methods for class attributes. Closes #7401 [Rick]
* Docs: validations examples. #7343 [zackchandler]
@@ -25,9 +25,7 @@ def quote(value, column = nil)
# BigDecimals need to be output in a non-normalized form and quoted.
when BigDecimal then value.to_s('F')
else
- if value.acts_like?(:date)
- "'#{value.to_s}'"
- elsif value.acts_like?(:time)
+ if value.acts_like?(:date) || value.acts_like?(:time)
"'#{quoted_date(value)}'"
else
"'#{quote_string(value.to_yaml)}'"
@@ -50,13 +48,13 @@ def quote_column_name(name)
def quoted_true
"'t'"
end
-
+
def quoted_false
"'f'"
end
-
+
def quoted_date(value)
- value.strftime("%Y-%m-%d %H:%M:%S")
+ value.to_s(:db)
end
end
end
@@ -125,8 +125,13 @@ def quote_column_name(name)
%("#{name}")
end
+ # Include microseconds if the value is a Time responding to usec.
def quoted_date(value)
- value.strftime("%Y-%m-%d %H:%M:%S.#{sprintf("%06d", value.usec)}")
+ if value.acts_like?(:time) && value.respond_to?(:usec)
+ "#{super}.#{sprintf("%06d", value.usec)}"
+ else
+ super
+ end
end

0 comments on commit c6b15dd

Please sign in to comment.