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

Changeset 9206

Show
Ignore:
Timestamp:
04/01/08 23:25:03 (8 months ago)
Author:
sam
Message:

Add TzinfoTimezone#dst_utc_offset

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • plugins/tzinfo_timezone/lib/tzinfo_timezone.rb

    r6093 r9206  
    179179    tzinfo.now 
    180180  end 
     181   
     182  # Returns the UTC offset of this time zone adjusted for DST at the 
     183  # current time, or optionally at the time specified by +relative_to+. 
     184  def dst_utc_offset(relative_to = now) 
     185    dst_offset = tzinfo.period_for_local(relative_to, true).dst? ? 3600 : 0 
     186    utc_offset + dst_offset 
     187  end 
    181188 
    182189  # Return the current date in this time zone. 
  • plugins/tzinfo_timezone/test/tzinfo_timezone_test.rb

    r4105 r9206  
    2121    end 
    2222  end 
     23   
     24  def test_dst_utc_offset_in_standard_time 
     25    zone = TzinfoTimezone["Central Time (US & Canada)"] 
     26    time = Time.utc(2008, 3, 9) 
     27    assert_equal zone.utc_offset, zone.dst_utc_offset(time) 
     28  end 
     29   
     30  def test_dst_utc_offset_in_daylight_time 
     31    zone = TzinfoTimezone["Central Time (US & Canada)"] 
     32    time = Time.utc(2008, 3, 9, 12) 
     33    assert_equal zone.utc_offset + 3600, zone.dst_utc_offset(time) 
     34  end 
    2335end