Class: ActiveRecord::Type::DateTime
- Includes:
- TimeValue
- Defined in:
- lib/active_record/type/date_time.rb
Overview
:nodoc:
Direct Known Subclasses
ConnectionAdapters::AbstractMysqlAdapter::MysqlDateTime, ConnectionAdapters::MysqlAdapter::Fields::DateTime, ConnectionAdapters::PostgreSQL::OID::DateTime
Instance Attribute Summary
Attributes inherited from Value
Instance Method Summary collapse
Methods included from TimeValue
Methods inherited from Value
#==, #binary?, #changed?, #changed_in_place?, #hash, #initialize, #klass, #number?, #text?, #type_cast_for_schema, #type_cast_from_database, #type_cast_from_user
Constructor Details
This class inherits a constructor from ActiveRecord::Type::Value
Instance Method Details
#type ⇒ Object
6 7 8 |
# File 'lib/active_record/type/date_time.rb', line 6 def type :datetime end |
#type_cast_for_database(value) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/active_record/type/date_time.rb', line 10 def type_cast_for_database(value) return super unless value.acts_like?(:time) zone_conversion_method = ActiveRecord::Base.default_timezone == :utc ? :getutc : :getlocal if value.respond_to?(zone_conversion_method) value = value.send(zone_conversion_method) end return value unless has_precision? result = value.to_s(:db) if value.respond_to?(:usec) && (1..6).cover?(precision) "#{result}.#{sprintf("%0#{precision}d", value.usec / 10 ** (6 - precision))}" else result end end |