diff options
-rw-r--r-- | activemodel/lib/active_model/type/helpers/time_value.rb | 7 | ||||
-rw-r--r-- | activerecord/lib/active_record/type.rb | 56 | ||||
-rw-r--r-- | activerecord/lib/active_record/type/date.rb | 7 | ||||
-rw-r--r-- | activerecord/lib/active_record/type/date_time.rb | 7 | ||||
-rw-r--r-- | activerecord/lib/active_record/type/internal/timezone.rb | 2 | ||||
-rw-r--r-- | activerecord/lib/active_record/type/time.rb | 8 | ||||
-rw-r--r-- | activerecord/lib/active_record/type/type_map.rb | 2 |
7 files changed, 43 insertions, 46 deletions
diff --git a/activemodel/lib/active_model/type/helpers/time_value.rb b/activemodel/lib/active_model/type/helpers/time_value.rb index 5a899d43ec..c55bb1e136 100644 --- a/activemodel/lib/active_model/type/helpers/time_value.rb +++ b/activemodel/lib/active_model/type/helpers/time_value.rb @@ -19,11 +19,11 @@ module ActiveModel value end - + def is_utc? ::Time.zone_default =~ 'UTC' end - + def default_timezone ::Time.zone_default end @@ -41,7 +41,6 @@ module ActiveModel def new_time(year, mon, mday, hour, min, sec, microsec, offset = nil) # Treat 0000-00-00 00:00:00 as nil. return if year.nil? || (year == 0 && mon == 0 && mday == 0) - if offset time = ::Time.utc(year, mon, mday, hour, min, sec, microsec) rescue nil @@ -53,7 +52,7 @@ module ActiveModel ::Time.public_send(default_timezone, year, mon, mday, hour, min, sec, microsec) rescue nil end end - + ISO_DATETIME = /\A(\d{4})-(\d\d)-(\d\d) (\d\d):(\d\d):(\d\d)(\.\d+)?\z/ # Doesn't handle time zones. diff --git a/activerecord/lib/active_record/type.rb b/activerecord/lib/active_record/type.rb index 5b089d66a0..28ab07e868 100644 --- a/activerecord/lib/active_record/type.rb +++ b/activerecord/lib/active_record/type.rb @@ -1,24 +1,12 @@ -require 'active_model/type/helpers' -require 'active_model/type/value' - -require 'active_model/type/big_integer' -require 'active_model/type/binary' -require 'active_model/type/boolean' -require 'active_model/type/date' -require 'active_model/type/date_time' -require 'active_model/type/decimal' -require 'active_model/type/decimal_without_scale' -require 'active_model/type/float' -require 'active_model/type/integer' -require 'active_model/type/string' -require 'active_model/type/text' -require 'active_model/type/time' -require 'active_model/type/unsigned_integer' - -require 'active_model/type/registry' +require 'active_model/type' require 'active_record/type/internal/abstract_json' require 'active_record/type/internal/timezone' + +require 'active_record/type/date' +require 'active_record/type/date_time' +require 'active_record/type/time' + require 'active_record/type/serialized' require 'active_record/type/adapter_specific_registry' @@ -56,29 +44,17 @@ module ActiveRecord end end - class Date < ActiveModel::Type::Date - include Internal::Timezone - end - - class DateTime < ActiveModel::Type::DateTime - include Internal::Timezone - end - class Time < ActiveModel::Type::Time - include Internal::Timezone - end - - Helpers = ActiveModel::Type::Helpers - BigInteger = ActiveModel::Type::BigInteger - Binary = ActiveModel::Type::Binary - Boolean = ActiveModel::Type::Boolean - Decimal = ActiveModel::Type::Decimal + BigInteger = ActiveModel::Type::BigInteger + Binary = ActiveModel::Type::Binary + Boolean = ActiveModel::Type::Boolean + Decimal = ActiveModel::Type::Decimal DecimalWithoutScale = ActiveModel::Type::DecimalWithoutScale - Float = ActiveModel::Type::Float - Integer = ActiveModel::Type::Integer - String = ActiveModel::Type::String - Text = ActiveModel::Type::Text - UnsignedInteger = ActiveModel::Type::UnsignedInteger - Value = ActiveModel::Type::Value + Float = ActiveModel::Type::Float + Integer = ActiveModel::Type::Integer + String = ActiveModel::Type::String + Text = ActiveModel::Type::Text + UnsignedInteger = ActiveModel::Type::UnsignedInteger + Value = ActiveModel::Type::Value register(:big_integer, Type::BigInteger, override: false) register(:binary, Type::Binary, override: false) diff --git a/activerecord/lib/active_record/type/date.rb b/activerecord/lib/active_record/type/date.rb new file mode 100644 index 0000000000..ccafed054e --- /dev/null +++ b/activerecord/lib/active_record/type/date.rb @@ -0,0 +1,7 @@ +module ActiveRecord + module Type + class Date < ActiveModel::Type::Date + include Internal::Timezone + end + end +end diff --git a/activerecord/lib/active_record/type/date_time.rb b/activerecord/lib/active_record/type/date_time.rb new file mode 100644 index 0000000000..1fb9380ecd --- /dev/null +++ b/activerecord/lib/active_record/type/date_time.rb @@ -0,0 +1,7 @@ +module ActiveRecord + module Type + class DateTime < ActiveModel::Type::DateTime + include Internal::Timezone + end + end +end diff --git a/activerecord/lib/active_record/type/internal/timezone.rb b/activerecord/lib/active_record/type/internal/timezone.rb index 07dbb0b2c6..947e06158a 100644 --- a/activerecord/lib/active_record/type/internal/timezone.rb +++ b/activerecord/lib/active_record/type/internal/timezone.rb @@ -5,7 +5,7 @@ module ActiveRecord def is_utc? ActiveRecord::Base.default_timezone == :utc end - + def default_timezone ActiveRecord::Base.default_timezone end diff --git a/activerecord/lib/active_record/type/time.rb b/activerecord/lib/active_record/type/time.rb new file mode 100644 index 0000000000..70988d84ff --- /dev/null +++ b/activerecord/lib/active_record/type/time.rb @@ -0,0 +1,8 @@ +module ActiveRecord + module Type + class Time < ActiveModel::Type::Time + include Internal::Timezone + end + end +end + diff --git a/activerecord/lib/active_record/type/type_map.rb b/activerecord/lib/active_record/type/type_map.rb index 8ce36cc9af..81d7ed39bb 100644 --- a/activerecord/lib/active_record/type/type_map.rb +++ b/activerecord/lib/active_record/type/type_map.rb @@ -57,7 +57,7 @@ module ActiveRecord end def default_value - @default_value ||= Value.new + @default_value ||= ActiveModel::Type::Value.new end end end |