diff options
author | Pablo Herrero <pablodherrero@gmail.com> | 2014-10-18 04:47:40 -0300 |
---|---|---|
committer | Pablo Herrero <pablodherrero@gmail.com> | 2014-10-27 21:43:12 -0300 |
commit | 1897d3a5d240a962dc89d2cab1d36bedb08974f7 (patch) | |
tree | 9a96219e7ae59539b9dd4f6b20aeaaa34b84c1c4 /activesupport/lib | |
parent | d616fec8117ac25753ee23e15ac14261d298ee51 (diff) | |
download | rails-1897d3a5d240a962dc89d2cab1d36bedb08974f7.tar.gz rails-1897d3a5d240a962dc89d2cab1d36bedb08974f7.tar.bz2 rails-1897d3a5d240a962dc89d2cab1d36bedb08974f7.zip |
Optimize TimeWithZoneTest#strftime
Diffstat (limited to 'activesupport/lib')
-rw-r--r-- | activesupport/lib/active_support/time_with_zone.rb | 16 |
1 files changed, 6 insertions, 10 deletions
diff --git a/activesupport/lib/active_support/time_with_zone.rb b/activesupport/lib/active_support/time_with_zone.rb index 4a0ed356b1..dbee145196 100644 --- a/activesupport/lib/active_support/time_with_zone.rb +++ b/activesupport/lib/active_support/time_with_zone.rb @@ -75,8 +75,8 @@ module ActiveSupport # Returns a <tt>Time.local()</tt> instance of the simultaneous time in your # system's <tt>ENV['TZ']</tt> zone. - def localtime - utc.respond_to?(:getlocal) ? utc.getlocal : utc.to_time.getlocal + def localtime(utc_offset = nil) + utc.respond_to?(:getlocal) ? utc.getlocal(utc_offset) : utc.to_time.getlocal(utc_offset) end alias_method :getlocal, :localtime @@ -201,15 +201,11 @@ module ActiveSupport end alias_method :to_formatted_s, :to_s - # Replaces <tt>%Z</tt> and <tt>%z</tt> directives with +zone+ and - # +formatted_offset+, respectively, before passing to Time#strftime, so - # that zone information is correct + # Replaces <tt>%Z</tt> directive with +zone before passing to Time#strftime, + # so that zone information is correct. def strftime(format) - format = format.gsub('%Z', zone) - .gsub('%z', formatted_offset(false)) - .gsub('%:z', formatted_offset(true)) - .gsub('%::z', formatted_offset(true) + ":00") - time.strftime(format) + format = format.gsub(/((?:\A|[^%])(?:%%)*)%Z/, "\\1#{zone}") + getlocal(utc_offset).strftime(format) end # Use the time in UTC for comparisons. |