aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/type/date.rb
diff options
context:
space:
mode:
authorKir Shatrov <shatrov@me.com>2015-09-07 21:20:15 +0300
committerSean Griffin <sean@seantheprogrammer.com>2015-09-21 10:12:13 -0600
commit9cc8c6f3730df3d94c81a55be9ee1b7b4ffd29f6 (patch)
tree68a48d84f3d2e1902d94316f781c4aee60a5f798 /activerecord/lib/active_record/type/date.rb
parentb223d729d823dcf3c6915daa2bf48c028718c465 (diff)
downloadrails-9cc8c6f3730df3d94c81a55be9ee1b7b4ffd29f6.tar.gz
rails-9cc8c6f3730df3d94c81a55be9ee1b7b4ffd29f6.tar.bz2
rails-9cc8c6f3730df3d94c81a55be9ee1b7b4ffd29f6.zip
Move ActiveRecord::Type to ActiveModel
The first step of bringing typecasting to ActiveModel
Diffstat (limited to 'activerecord/lib/active_record/type/date.rb')
-rw-r--r--activerecord/lib/active_record/type/date.rb49
1 files changed, 0 insertions, 49 deletions
diff --git a/activerecord/lib/active_record/type/date.rb b/activerecord/lib/active_record/type/date.rb
deleted file mode 100644
index 3ceab59ebb..0000000000
--- a/activerecord/lib/active_record/type/date.rb
+++ /dev/null
@@ -1,49 +0,0 @@
-module ActiveRecord
- module Type
- class Date < Value # :nodoc:
- include Helpers::AcceptsMultiparameterTime.new
-
- def type
- :date
- end
-
- def type_cast_for_schema(value)
- "'#{value.to_s(:db)}'"
- end
-
- private
-
- def cast_value(value)
- if value.is_a?(::String)
- return if value.empty?
- fast_string_to_date(value) || fallback_string_to_date(value)
- elsif value.respond_to?(:to_date)
- value.to_date
- else
- value
- end
- end
-
- def fast_string_to_date(string)
- if string =~ ConnectionAdapters::Column::Format::ISO_DATE
- new_date $1.to_i, $2.to_i, $3.to_i
- end
- end
-
- def fallback_string_to_date(string)
- new_date(*::Date._parse(string, false).values_at(:year, :mon, :mday))
- end
-
- def new_date(year, mon, mday)
- if year && year != 0
- ::Date.new(year, mon, mday) rescue nil
- end
- end
-
- def value_from_multiparameter_assignment(*)
- time = super
- time && time.to_date
- end
- end
- end
-end