Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Changeset 8635

Show
Ignore:
Timestamp:
01/12/08 20:44:31 (8 months ago)
Author:
gbuesing
Message:

Refactor number-to-HH:MM-string conversion logic from TimeZone#formatted_offset to reusable Numeric#to_utc_offset_s method

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/activesupport/CHANGELOG

    r8570 r8635  
    11*SVN* 
     2 
     3* Refactor number-to-HH:MM-string conversion logic from TimeZone#formatted_offset to a reusable Numeric#to_utc_offset_s method. [Geoff Buesing] 
    24 
    35* Continue evolution toward ActiveSupport::TestCase.  #10679 [Josh Peek] 
  • trunk/activesupport/lib/active_support/core_ext/numeric.rb

    r7719 r8635  
    11require 'active_support/core_ext/numeric/time' 
    22require 'active_support/core_ext/numeric/bytes' 
     3require 'active_support/core_ext/numeric/conversions' 
    34 
    45class Numeric #:nodoc: 
    56  include ActiveSupport::CoreExtensions::Numeric::Time  
    6   include ActiveSupport::CoreExtensions::Numeric::Bytes  
     7  include ActiveSupport::CoreExtensions::Numeric::Bytes 
     8  include ActiveSupport::CoreExtensions::Numeric::Conversions  
    79end 
  • trunk/activesupport/lib/active_support/values/time_zone.rb

    r8370 r8635  
    2727  def formatted_offset( colon=true ) 
    2828    return "" if utc_offset == 0 
    29     sign = (utc_offset < 0 ? -1 : 1) 
    30     hours = utc_offset.abs / 3600 
    31     minutes = (utc_offset.abs % 3600) / 60 
    32     "%+03d%s%02d" % [ hours * sign, colon ? ":" : "", minutes ] 
     29    utc_offset.to_utc_offset_s(colon) 
    3330  end 
    3431 
  • trunk/activesupport/test/core_ext/numeric_ext_test.rb

    r8563 r8635  
    146146  end 
    147147end 
     148 
     149class NumericExtConversionsTest < Test::Unit::TestCase 
     150   
     151  def test_to_utc_offset_s_with_colon 
     152    assert_equal "-06:00", -21_600.to_utc_offset_s 
     153    assert_equal "+00:00", 0.to_utc_offset_s 
     154    assert_equal "+05:00", 18_000.to_utc_offset_s 
     155  end 
     156   
     157  def test_to_utc_offset_s_without_colon 
     158    assert_equal "-0600", -21_600.to_utc_offset_s(false) 
     159    assert_equal "+0000", 0.to_utc_offset_s(false) 
     160    assert_equal "+0500", 18_000.to_utc_offset_s(false) 
     161  end 
     162end