diff options
author | denisovlev <denisovlev@ya.ru> | 2016-10-20 15:44:22 +0300 |
---|---|---|
committer | denisovlev <denisovlev@ya.ru> | 2016-10-21 13:19:08 +0300 |
commit | 07ffe7a6211b2bac59f385f4a0a67d11e4d42c24 (patch) | |
tree | da000295e5dd71d11eebfea28a35581bf828362e /activesupport/lib/active_support/values | |
parent | f2c6db41ba56afb1529e4732c59622fc0cf9f3ba (diff) | |
download | rails-07ffe7a6211b2bac59f385f4a0a67d11e4d42c24.tar.gz rails-07ffe7a6211b2bac59f385f4a0a67d11e4d42c24.tar.bz2 rails-07ffe7a6211b2bac59f385f4a0a67d11e4d42c24.zip |
Fix `ActiveSupport::TimeZone#strptime` cannot parse timestamps (%Q, %s)
Diffstat (limited to 'activesupport/lib/active_support/values')
-rw-r--r-- | activesupport/lib/active_support/values/time_zone.rb | 26 |
1 files changed, 15 insertions, 11 deletions
diff --git a/activesupport/lib/active_support/values/time_zone.rb b/activesupport/lib/active_support/values/time_zone.rb index cb97a0e135..a562f33420 100644 --- a/activesupport/lib/active_support/values/time_zone.rb +++ b/activesupport/lib/active_support/values/time_zone.rb @@ -450,17 +450,21 @@ module ActiveSupport raise ArgumentError, "invalid date" if parts.nil? return if parts.empty? - time = Time.new( - parts.fetch(:year, now.year), - parts.fetch(:mon, now.month), - parts.fetch(:mday, parts[:year] || parts[:mon] ? 1 : now.day), - parts.fetch(:hour, 0), - parts.fetch(:min, 0), - parts.fetch(:sec, 0) + parts.fetch(:sec_fraction, 0), - parts.fetch(:offset, 0) - ) - - if parts[:offset] + if parts[:seconds] + time = Time.at(parts[:seconds]) + else + time = Time.new( + parts.fetch(:year, now.year), + parts.fetch(:mon, now.month), + parts.fetch(:mday, parts[:year] || parts[:mon] ? 1 : now.day), + parts.fetch(:hour, 0), + parts.fetch(:min, 0), + parts.fetch(:sec, 0) + parts.fetch(:sec_fraction, 0), + parts.fetch(:offset, 0) + ) + end + + if parts[:offset] || parts[:seconds] TimeWithZone.new(time.utc, self) else TimeWithZone.new(nil, self, time) |