Changeset 8852
- Timestamp:
- 02/10/08 20:04:14 (5 months ago)
- Files:
-
- trunk/activesupport/CHANGELOG (modified) (1 diff)
- trunk/activesupport/lib/active_support/time_with_zone.rb (modified) (3 diffs)
- trunk/activesupport/test/core_ext/time_with_zone_test.rb (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/activesupport/CHANGELOG
r8851 r8852 1 1 *SVN* 2 3 * Adding TimeWithZone #to_a, #to_f, #to_i, #httpdate, #rfc2822 [Geoff Buesing] 2 4 3 5 * Pruning unneeded TimeWithZone#change_time_zone_to_current [Geoff Buesing] trunk/activesupport/lib/active_support/time_with_zone.rb
r8851 r8852 45 45 # Returns a Time.local() instance of the simultaneous time in your system's ENV['TZ'] zone 46 46 def localtime 47 utc. dup.localtime # use #dup because Time#localtime is destructive47 utc.getlocal 48 48 end 49 49 … … 80 80 %("#{time.strftime("%Y/%m/%d %H:%M:%S")} #{formatted_offset(false)}") 81 81 end 82 83 def httpdate 84 utc.httpdate 85 end 86 87 def rfc2822 88 to_s(:rfc822) 89 end 90 alias_method :rfc822, :rfc2822 82 91 83 92 # :db format outputs time in UTC; all others output time in local. Uses TimeWithZone's strftime, so %Z and %z work correctly … … 107 116 def -(other) 108 117 other.acts_like?(:time) ? utc - other : method_missing(:-, other) 118 end 119 120 def to_a 121 time.to_a[0, 8].push(dst?, zone) 122 end 123 124 def to_f 125 utc.to_f 126 end 127 128 def to_i 129 utc.to_i 109 130 end 110 131 trunk/activesupport/test/core_ext/time_with_zone_test.rb
r8850 r8852 83 83 end 84 84 85 def test_httpdate 86 assert_equal 'Sat, 01 Jan 2000 00:00:00 GMT', @twz.httpdate 87 end 88 89 def test_rfc2822 90 assert_equal "Fri, 31 Dec 1999 19:00:00 -0500", @twz.rfc2822 91 end 92 85 93 def test_compare_with_time 86 94 assert_equal 1, @twz <=> Time.utc(1999, 12, 31, 23, 59, 59) … … 126 134 twz2 = ActiveSupport::TimeWithZone.new( Time.utc(2000, 1, 2), TimeZone['UTC'] ) 127 135 assert_equal 86_400.0, twz2 - twz1 136 end 137 138 def test_to_a 139 assert_equal [45, 30, 5, 1, 2, 2000, 2, 32, false, "HST"], ActiveSupport::TimeWithZone.new( Time.utc(2000, 2, 1, 15, 30, 45), TimeZone['Hawaii'] ).to_a 140 end 141 142 def test_to_f 143 result = ActiveSupport::TimeWithZone.new( Time.utc(2000, 1, 1), TimeZone['Hawaii'] ).to_f 144 assert_equal 946684800.0, result 145 assert result.is_a?(Float) 146 end 147 148 def test_to_i 149 result = ActiveSupport::TimeWithZone.new( Time.utc(2000, 1, 1), TimeZone['Hawaii'] ).to_i 150 assert_equal 946684800, result 151 assert result.is_a?(Integer) 128 152 end 129 153