public
Description: Ruby on Rails
Homepage: http://rubyonrails.org
Clone URL: git://github.com/rails/rails.git
Search Repo:
Merge branch 'master' of git://github.com/rails/rails
dhh (author)
Sun Apr 13 15:28:14 -0700 2008
commit  be7fd8168aa4776dccfe2e670cb9451204449dd4
tree    dd0f9e7d7dca2899449fa9c2faa240bc5f803e64
parent  342dcfe789d11e07f89d4ddfc3dc581da650a65e parent  9620372a6dc7eeebdb04f1fdb7f150d29e60fc00
...
1
2
 
 
 
 
 
 
 
 
3
4
5
...
1
2
3
4
5
6
7
8
9
10
11
12
13
0
@@ -1,5 +1,13 @@
0
 *SVN*
0
 
0
+* Time#since behaves correctly when passed a Duration. Closes #11527 [kemiller]
0
+
0
+* Add #getutc alias for DateTime#utc [Geoff Buesing]
0
+
0
+* Refactor TimeWithZone: don't send #since, #ago, #+, #-, #advance through method_missing [Geoff Buesing]
0
+
0
+* TimeWithZone respects config.active_support.use_standard_json_time_format [Geoff Buesing]
0
+
0
 * Add config.active_support.escape_html_entities_in_json to allow disabling of html entity escaping. [rick]
0
 
0
 * Improve documentation. [Xavier Noria]
...
86
87
88
 
89
90
91
...
86
87
88
89
90
91
92
0
@@ -86,6 +86,7 @@
0
         def utc
0
           new_offset(0)
0
         end
0
+ alias_method :getutc, :utc
0
         
0
         # Returns true if offset == 0
0
         def utc?
...
88
89
90
91
92
93
94
95
96
97
 
98
99
100
101
102
 
 
 
 
 
 
 
103
104
105
...
88
89
90
 
91
92
93
94
95
 
96
97
 
98
 
 
99
100
101
102
103
104
105
106
107
108
0
@@ -88,18 +88,21 @@
0
         end
0
 
0
         # Returns a new Time representing the time a number of seconds ago, this is basically a wrapper around the Numeric extension
0
- # Do not use this method in combination with x.months, use months_ago instead!
0
         def ago(seconds)
0
           self.since(-seconds)
0
         end
0
 
0
         # Returns a new Time representing the time a number of seconds since the instance time, this is basically a wrapper around
0
- # the Numeric extension. Do not use this method in combination with x.months, use months_since instead!
0
+ # the Numeric extension.
0
         def since(seconds)
0
- initial_dst = self.dst? ? 1 : 0
0
           f = seconds.since(self)
0
- final_dst = f.dst? ? 1 : 0
0
- (seconds.abs >= 86400 && initial_dst != final_dst) ? f + (initial_dst - final_dst).hours : f
0
+ if ActiveSupport::Duration === seconds
0
+ f
0
+ else
0
+ initial_dst = self.dst? ? 1 : 0
0
+ final_dst = f.dst? ? 1 : 0
0
+ (seconds.abs >= 86400 && initial_dst != final_dst) ? f + (initial_dst - final_dst).hours : f
0
+ end
0
         rescue
0
           self.to_datetime.since(seconds)
0
         end
...
77
78
79
80
 
 
 
 
 
81
82
83
...
130
131
132
133
 
 
134
135
136
137
...
140
141
142
143
 
 
144
145
146
 
 
 
 
 
 
 
 
 
 
 
 
147
148
149
...
204
205
206
207
208
209
210
211
212
213
 
 
214
215
216
...
77
78
79
 
80
81
82
83
84
85
86
87
...
134
135
136
 
137
138
139
140
141
142
...
145
146
147
 
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
...
222
223
224
 
 
 
 
 
 
 
225
226
227
228
229
0
@@ -77,7 +77,11 @@
0
     alias_method :iso8601, :xmlschema
0
   
0
     def to_json(options = nil)
0
- %("#{time.strftime("%Y/%m/%d %H:%M:%S")} #{formatted_offset(false)}")
0
+ if ActiveSupport.use_standard_json_time_format
0
+ utc.xmlschema.inspect
0
+ else
0
+ %("#{time.strftime("%Y/%m/%d %H:%M:%S")} #{formatted_offset(false)}")
0
+ end
0
     end
0
     
0
     def to_yaml(options = {})
0
@@ -130,7 +134,8 @@
0
     # If wrapped #time is a DateTime, use DateTime#since instead of #+
0
     # Otherwise, just pass on to #method_missing
0
     def +(other)
0
- time.acts_like?(:date) ? method_missing(:since, other) : method_missing(:+, other)
0
+ result = utc.acts_like?(:date) ? utc.since(other) : utc + other
0
+ result.in_time_zone(time_zone)
0
     end
0
     
0
     # If a time-like object is passed in, compare it with #utc
0
0
@@ -140,10 +145,23 @@
0
       if other.acts_like?(:time)
0
         utc - other
0
       else
0
- time.acts_like?(:date) ? method_missing(:ago, other) : method_missing(:-, other)
0
+ result = utc.acts_like?(:date) ? utc.ago(other) : utc - other
0
+ result.in_time_zone(time_zone)
0
       end
0
     end
0
     
0
+ def since(other)
0
+ utc.since(other).in_time_zone(time_zone)
0
+ end
0
+
0
+ def ago(other)
0
+ utc.ago(other).in_time_zone(time_zone)
0
+ end
0
+
0
+ def advance(options)
0
+ utc.advance(options).in_time_zone(time_zone)
0
+ end
0
+
0
     def usec
0
       time.respond_to?(:usec) ? time.usec : 0
0
     end
0
@@ -204,13 +222,8 @@
0
   
0
     # Send the missing method to time instance, and wrap result in a new TimeWithZone with the existing time_zone
0
     def method_missing(sym, *args, &block)
0
- if %w(+ - since ago advance).include?(sym.to_s)
0
- result = utc.__send__(sym, *args, &block)
0
- result.acts_like?(:time) ? result.in_time_zone(time_zone) : result
0
- else
0
- result = time.__send__(sym, *args, &block)
0
- result.acts_like?(:time) ? self.class.new(nil, time_zone, result) : result
0
- end
0
+ result = time.__send__(sym, *args, &block)
0
+ result.acts_like?(:time) ? self.class.new(nil, time_zone, result) : result
0
     end
0
     
0
     private
...
240
241
242
 
243
244
245
...
240
241
242
243
244
245
246
0
@@ -240,6 +240,7 @@
0
     assert_equal DateTime.civil(2005, 2, 21, 15, 11, 12, 0), DateTime.civil(2005, 2, 21, 10, 11, 12, Rational(-5, 24)).utc
0
     assert_equal DateTime.civil(2005, 2, 21, 10, 11, 12, 0), DateTime.civil(2005, 2, 21, 10, 11, 12, 0).utc
0
     assert_equal DateTime.civil(2005, 2, 21, 9, 11, 12, 0), DateTime.civil(2005, 2, 21, 10, 11, 12, Rational(1, 24)).utc
0
+ assert_equal DateTime.civil(2005, 2, 21, 9, 11, 12, 0), DateTime.civil(2005, 2, 21, 10, 11, 12, Rational(1, 24)).getutc
0
   end
0
   
0
   def test_formatted_offset_with_utc
...
205
206
207
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
208
209
210
...
227
228
229
 
 
 
 
 
 
 
 
 
 
 
 
 
230
231
232
...
240
241
242
243
 
244
245
246
...
266
267
268
 
 
 
 
 
 
 
 
 
 
 
 
 
269
270
271
...
279
280
281
282
 
283
284
285
...
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
...
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
...
278
279
280
 
281
282
283
284
...
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
...
330
331
332
 
333
334
335
336
0
@@ -205,6 +205,31 @@
0
     end
0
   end
0
 
0
+ def test_daylight_savings_time_crossings_backward_start_1day
0
+ with_env_tz 'US/Eastern' do
0
+ # dt: US: 2005 April 3rd 4:18am
0
+ assert_equal Time.local(2005,4,2,4,18,0), Time.local(2005,4,3,4,18,0).ago(1.day), 'dt-1.day=>st'
0
+ assert_equal Time.local(2005,4,1,4,18,0), Time.local(2005,4,2,4,18,0).ago(1.day), 'st-1.day=>st'
0
+ end
0
+ with_env_tz 'NZ' do
0
+ # dt: New Zealand: 2006 October 1st 4:18am
0
+ assert_equal Time.local(2006,9,30,4,18,0), Time.local(2006,10,1,4,18,0).ago(1.day), 'dt-1.day=>st'
0
+ assert_equal Time.local(2006,9,29,4,18,0), Time.local(2006,9,30,4,18,0).ago(1.day), 'st-1.day=>st'
0
+ end
0
+ end
0
+
0
+ def test_daylight_savings_time_crossings_backward_end_1day
0
+ with_env_tz 'US/Eastern' do
0
+ # st: US: 2005 October 30th 4:03am
0
+ assert_equal Time.local(2005,10,29,4,3), Time.local(2005,10,30,4,3,0).ago(1.day), 'st-1.day=>dt'
0
+ assert_equal Time.local(2005,10,28,4,3), Time.local(2005,10,29,4,3,0).ago(1.day), 'dt-1.day=>dt'
0
+ end
0
+ with_env_tz 'NZ' do
0
+ # st: New Zealand: 2006 March 19th 4:03am
0
+ assert_equal Time.local(2006,3,18,4,3), Time.local(2006,3,19,4,3,0).ago(1.day), 'st-1.day=>dt'
0
+ assert_equal Time.local(2006,3,17,4,3), Time.local(2006,3,18,4,3,0).ago(1.day), 'dt-1.day=>dt'
0
+ end
0
+ end
0
   def test_since
0
     assert_equal Time.local(2005,2,22,10,10,11), Time.local(2005,2,22,10,10,10).since(1)
0
     assert_equal Time.local(2005,2,22,11,10,10), Time.local(2005,2,22,10,10,10).since(3600)
0
@@ -227,6 +252,19 @@
0
     end
0
   end
0
 
0
+ def test_daylight_savings_time_crossings_forward_start_1day
0
+ with_env_tz 'US/Eastern' do
0
+ # st: US: 2005 April 2nd 7:27pm
0
+ assert_equal Time.local(2005,4,3,19,27,0), Time.local(2005,4,2,19,27,0).since(1.day), 'st+1.day=>dt'
0
+ assert_equal Time.local(2005,4,4,19,27,0), Time.local(2005,4,3,19,27,0).since(1.day), 'dt+1.day=>dt'
0
+ end
0
+ with_env_tz 'NZ' do
0
+ # st: New Zealand: 2006 September 30th 7:27pm
0
+ assert_equal Time.local(2006,10,1,19,27,0), Time.local(2006,9,30,19,27,0).since(1.day), 'st+1.day=>dt'
0
+ assert_equal Time.local(2006,10,2,19,27,0), Time.local(2006,10,1,19,27,0).since(1.day), 'dt+1.day=>dt'
0
+ end
0
+ end
0
+
0
   def test_daylight_savings_time_crossings_forward_start_tomorrow
0
     with_env_tz 'US/Eastern' do
0
       # st: US: 2005 April 2nd 7:27pm
0
@@ -240,7 +278,7 @@
0
     end
0
   end
0
 
0
- def test_daylight_savings_time_crossings_forward_start_yesterday
0
+ def test_daylight_savings_time_crossings_backward_start_yesterday
0
     with_env_tz 'US/Eastern' do
0
       # st: US: 2005 April 2nd 7:27pm
0
       assert_equal Time.local(2005,4,2,19,27,0), Time.local(2005,4,3,19,27,0).yesterday, 'dt-1.day=>st'
0
@@ -266,6 +304,19 @@
0
     end
0
   end
0
 
0
+ def test_daylight_savings_time_crossings_forward_end_1day
0
+ with_env_tz 'US/Eastern' do
0
+ # dt: US: 2005 October 30th 12:45am
0
+ assert_equal Time.local(2005,10,31,0,45,0), Time.local(2005,10,30,0,45,0).since(1.day), 'dt+1.day=>st'
0
+ assert_equal Time.local(2005,11, 1,0,45,0), Time.local(2005,10,31,0,45,0).since(1.day), 'st+1.day=>st'
0
+ end
0
+ with_env_tz 'NZ' do
0
+ # dt: New Zealand: 2006 March 19th 1:45am
0
+ assert_equal Time.local(2006,3,20,1,45,0), Time.local(2006,3,19,1,45,0).since(1.day), 'dt+1.day=>st'
0
+ assert_equal Time.local(2006,3,21,1,45,0), Time.local(2006,3,20,1,45,0).since(1.day), 'st+1.day=>st'
0
+ end
0
+ end
0
+
0
   def test_daylight_savings_time_crossings_forward_end_tomorrow
0
     with_env_tz 'US/Eastern' do
0
       # dt: US: 2005 October 30th 12:45am
0
@@ -279,7 +330,7 @@
0
     end
0
   end
0
 
0
- def test_daylight_savings_time_crossings_forward_end_yesterday
0
+ def test_daylight_savings_time_crossings_backward_end_yesterday
0
     with_env_tz 'US/Eastern' do
0
       # dt: US: 2005 October 30th 12:45am
0
       assert_equal Time.local(2005,10,30,0,45,0), Time.local(2005,10,31,0,45,0).yesterday, 'st-1.day=>dt'
...
67
68
69
 
 
 
 
 
 
 
70
71
72
...
67
68
69
70
71
72
73
74
75
76
77
78
79
0
@@ -67,6 +67,13 @@
0
       assert_equal "\"1999/12/31 19:00:00 -0500\"", @twz.to_json
0
     end
0
   end
0
+
0
+ def test_to_json_with_use_standard_json_time_format_config_set_to_true
0
+ old, ActiveSupport.use_standard_json_time_format = ActiveSupport.use_standard_json_time_format, true
0
+ assert_equal "\"2000-01-01T00:00:00Z\"", @twz.to_json
0
+ ensure
0
+ ActiveSupport.use_standard_json_time_format = old
0
+ end
0
     
0
   def test_strftime
0
     silence_warnings do # silence warnings raised by tzinfo gem
...
1
2
 
 
3
4
5
...
1
2
3
4
5
6
7
0
@@ -1,5 +1,7 @@
0
 *SVN*
0
 
0
+* rake time:zones:local finds correct base utc offset for zones in the Southern Hemisphere [Geoff Buesing]
0
+
0
 * Don't require rails/gem_builder during rails initialization, it's only needed for the gems:build task. [rick]
0
 
0
 * script/performance/profiler compatibility with the ruby-prof >= 0.5.0. Closes #9176. [Catfish]
...
24
25
26
27
 
 
 
 
28
29
30
...
24
25
26
 
27
28
29
30
31
32
33
0
@@ -24,7 +24,10 @@
0
     
0
     desc 'Displays names of time zones recognized by the Rails TimeZone class with the same offset as the system local time'
0
     task :local do
0
- build_time_zone_list(:all, Time.now.beginning_of_year.utc_offset)
0
+ jan_offset = Time.now.beginning_of_year.utc_offset
0
+ jul_offset = Time.now.beginning_of_year.change(:month => 7).utc_offset
0
+ offset = jan_offset < jul_offset ? jan_offset : jul_offset
0
+ build_time_zone_list(:all, offset)
0
     end
0
     
0
     # to find UTC -06:00 zones, OFFSET can be set to either -6, -6:00 or 21600

Comments

    No one has commented yet.