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

Changeset 8697

Show
Ignore:
Timestamp:
01/23/08 02:11:00 (4 months ago)
Author:
gbuesing
Message:

Adding alternate_utc_string option to TimeZone#formatted_offset. Removing unneeded TimeZone#offset

Files:

Legend:

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

    r8696 r8697  
    11*SVN* 
     2 
     3* Adding alternate_utc_string option to TimeZone#formatted_offset. Removing unneeded TimeZone#offset. [Geoff Buesing] 
    24 
    35* Introduce ActiveSupport::TimeWithZone, for wrapping Time instances with a TimeZone. Introduce instance methods to Time for creating TimeWithZone instances, and class methods for managing a global time zone. [Geoff Buesing] 
  • trunk/activesupport/lib/active_support/values/time_zone.rb

    r8679 r8697  
    157157 
    158158  # Returns the offset of this time zone as a formatted string, of the 
    159   # format "+HH:MM". If the offset is zero, this returns the empty 
    160   # string. If +colon+ is false, a colon will not be inserted into the 
    161   # result. 
    162   def formatted_offset(colon=true) 
    163     utc_offset == 0 ? '' : offset(colon) 
    164   end 
    165    
    166   # Returns the offset of this time zone as a formatted string, of the 
    167159  # format "+HH:MM". 
    168   def offset(colon=true
    169     utc_offset.to_utc_offset_s(colon) 
     160  def formatted_offset(colon=true, alternate_utc_string = nil
     161    utc_offset == 0 && alternate_utc_string || utc_offset.to_utc_offset_s(colon) 
    170162  end 
    171163 
  • trunk/activesupport/test/time_zone_test.rb

    r8679 r8697  
    7878  end 
    7979   
     80  def test_formatted_offset_zero 
     81    zone = TimeZone['London'] 
     82    assert_equal "+00:00", zone.formatted_offset 
     83    assert_equal "UTC", zone.formatted_offset(true, 'UTC') 
     84  end 
     85   
    8086  def test_zone_compare 
    8187    zone1 = TimeZone['Central Time (US & Canada)'] # offset -0600