diff options
author | Ryuta Kamizono <kamipo@gmail.com> | 2019-02-18 03:16:23 +0900 |
---|---|---|
committer | Ryuta Kamizono <kamipo@gmail.com> | 2019-02-18 04:20:52 +0900 |
commit | 907280ddfd78c53e2eb5af6f12512dc38df38bd8 (patch) | |
tree | 445db778f4e92d73acec0896e068f978c7ed6383 /activemodel/lib/active_model/type/helpers | |
parent | 07346c4b35df191cfb05353a0a9f3e2f30faca65 (diff) | |
download | rails-907280ddfd78c53e2eb5af6f12512dc38df38bd8.tar.gz rails-907280ddfd78c53e2eb5af6f12512dc38df38bd8.tar.bz2 rails-907280ddfd78c53e2eb5af6f12512dc38df38bd8.zip |
Fix type cast with values hash for Date type
`value_from_multiparameter_assignment` defined by
`AcceptsMultiparameterTime` helper requires `default_timezone` method
which is defined at `TimeValue` helper.
Since `Date` type doesn't include `TimeValue`, I've extracted `Timezone`
helper to be shared by `Date`, `DateTime`, and `Time` types.
Diffstat (limited to 'activemodel/lib/active_model/type/helpers')
-rw-r--r-- | activemodel/lib/active_model/type/helpers/time_value.rb | 12 | ||||
-rw-r--r-- | activemodel/lib/active_model/type/helpers/timezone.rb | 19 |
2 files changed, 19 insertions, 12 deletions
diff --git a/activemodel/lib/active_model/type/helpers/time_value.rb b/activemodel/lib/active_model/type/helpers/time_value.rb index da56073436..735b9a75a6 100644 --- a/activemodel/lib/active_model/type/helpers/time_value.rb +++ b/activemodel/lib/active_model/type/helpers/time_value.rb @@ -21,18 +21,6 @@ module ActiveModel value end - def is_utc? - ::Time.zone_default.nil? || ::Time.zone_default =~ "UTC" - end - - def default_timezone - if is_utc? - :utc - else - :local - end - end - def apply_seconds_precision(value) return value unless precision && value.respond_to?(:usec) number_of_insignificant_digits = 6 - precision diff --git a/activemodel/lib/active_model/type/helpers/timezone.rb b/activemodel/lib/active_model/type/helpers/timezone.rb new file mode 100644 index 0000000000..cf87b9715b --- /dev/null +++ b/activemodel/lib/active_model/type/helpers/timezone.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +require "active_support/core_ext/time/zones" + +module ActiveModel + module Type + module Helpers # :nodoc: all + module Timezone + def is_utc? + ::Time.zone_default.nil? || ::Time.zone_default =~ "UTC" + end + + def default_timezone + is_utc? ? :utc : :local + end + end + end + end +end |