aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/values
diff options
context:
space:
mode:
authorPrem Sichanugrist <s@sikachu.com>2010-01-19 01:55:48 +0700
committerJosé Valim <jose.valim@gmail.com>2010-01-19 20:31:33 +0100
commit6e62e89737c991de712a13b67a282ce599710ec9 (patch)
tree780299730b616e9ca0fac6c91a89a9da14592297 /activesupport/lib/active_support/values
parentd2759d125ae64e6fd64c8bffe7b15568698654bf (diff)
downloadrails-6e62e89737c991de712a13b67a282ce599710ec9.tar.gz
rails-6e62e89737c991de712a13b67a282ce599710ec9.tar.bz2
rails-6e62e89737c991de712a13b67a282ce599710ec9.zip
Fix bug that causes TimeZone.seconds_to_utc_offset to returns wrong offset when hour < 0 and not in hundreds [#3741 status:resolved]
Signed-off-by: José Valim <jose.valim@gmail.com>
Diffstat (limited to 'activesupport/lib/active_support/values')
-rw-r--r--activesupport/lib/active_support/values/time_zone.rb7
1 files changed, 4 insertions, 3 deletions
diff --git a/activesupport/lib/active_support/values/time_zone.rb b/activesupport/lib/active_support/values/time_zone.rb
index cbb8e890ae..245d3ce051 100644
--- a/activesupport/lib/active_support/values/time_zone.rb
+++ b/activesupport/lib/active_support/values/time_zone.rb
@@ -172,7 +172,7 @@ module ActiveSupport
MAPPING.freeze
end
- UTC_OFFSET_WITH_COLON = '%+03d:%02d'
+ UTC_OFFSET_WITH_COLON = '%s%02d:%02d'
UTC_OFFSET_WITHOUT_COLON = UTC_OFFSET_WITH_COLON.sub(':', '')
# Assumes self represents an offset from UTC in seconds (as returned from Time#utc_offset)
@@ -181,9 +181,10 @@ module ActiveSupport
# TimeZone.seconds_to_utc_offset(-21_600) # => "-06:00"
def self.seconds_to_utc_offset(seconds, colon = true)
format = colon ? UTC_OFFSET_WITH_COLON : UTC_OFFSET_WITHOUT_COLON
- hours = seconds / 3600
+ sign = (seconds < 0 ? '-' : '+')
+ hours = seconds.abs / 3600
minutes = (seconds.abs % 3600) / 60
- format % [hours, minutes]
+ format % [sign, hours, minutes]
end
include Comparable