diff options
author | Ryuta Kamizono <kamipo@gmail.com> | 2019-06-18 13:55:13 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-06-18 13:55:13 +0900 |
commit | aeba121a83965d242ed6d7fd46e9c166079a3230 (patch) | |
tree | 6dc49f839a9e41cd68eb34ec01ed69350829afbf | |
parent | c65acad0df6b332324c24e725c7d581bd76f9760 (diff) | |
parent | d29d4598972e85df7ee42f5aa969b51d1b14d615 (diff) | |
download | rails-aeba121a83965d242ed6d7fd46e9c166079a3230.tar.gz rails-aeba121a83965d242ed6d7fd46e9c166079a3230.tar.bz2 rails-aeba121a83965d242ed6d7fd46e9c166079a3230.zip |
Merge pull request #36508 from kamipo/avoid_getutc
Avoid redundant `time.getutc` call if it is already utc time object
3 files changed, 10 insertions, 10 deletions
diff --git a/activemodel/lib/active_model/type/helpers/time_value.rb b/activemodel/lib/active_model/type/helpers/time_value.rb index 508fe77531..075e906034 100644 --- a/activemodel/lib/active_model/type/helpers/time_value.rb +++ b/activemodel/lib/active_model/type/helpers/time_value.rb @@ -11,10 +11,10 @@ module ActiveModel value = apply_seconds_precision(value) if value.acts_like?(:time) - zone_conversion_method = is_utc? ? :getutc : :getlocal - - if value.respond_to?(zone_conversion_method) - value = value.send(zone_conversion_method) + if is_utc? + value = value.getutc if value.respond_to?(:getutc) && !value.utc? + else + value = value.getlocal if value.respond_to?(:getlocal) end end diff --git a/activemodel/lib/active_model/type/value.rb b/activemodel/lib/active_model/type/value.rb index 994d135b7b..788ded3e96 100644 --- a/activemodel/lib/active_model/type/value.rb +++ b/activemodel/lib/active_model/type/value.rb @@ -110,7 +110,7 @@ module ActiveModel [self.class, precision, scale, limit].hash end - def assert_valid_value(*) + def assert_valid_value(_) end private diff --git a/activerecord/lib/active_record/connection_adapters/abstract/quoting.rb b/activerecord/lib/active_record/connection_adapters/abstract/quoting.rb index 1b6ba8ce97..93273f6cf6 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract/quoting.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract/quoting.rb @@ -114,16 +114,16 @@ module ActiveRecord # if the value is a Time responding to usec. def quoted_date(value) if 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) + if ActiveRecord::Base.default_timezone == :utc + value = value.getutc if value.respond_to?(:getutc) && !value.utc? + else + value = value.getlocal if value.respond_to?(:getlocal) end end result = value.to_s(:db) if value.respond_to?(:usec) && value.usec > 0 - "#{result}.#{sprintf("%06d", value.usec)}" + result << "." << sprintf("%06d", value.usec) else result end |