public
Description: Ruby on Rails
Homepage: http://rubyonrails.org
Clone URL: git://github.com/rails/rails.git
Search Repo:
Adding Date.current, which returns Time.zone.today if config.time_zone is 
set; otherwise returns Date.today. ActionView date_helper uses 
Date.current to determine locale-appropriate default
gbuesing (author)
Thu May 08 20:48:47 -0700 2008
commit  66728087d0eb99a524498e8f24725dae6073edd6
tree    e8675936450de56cc4603d9057668cc365ae7113
parent  79e44a5ee484f977c2cad8a4cffe882b816340a1
...
1
2
 
 
3
4
5
...
1
2
3
4
5
6
7
0
@@ -1,5 +1,7 @@
0
 *SVN*
0
 
0
+* select_date defaults to Time.zone.today when config.time_zone is set [Geoff Buesing]
0
+
0
 * Fixed that TextHelper#text_field would corrypt when raw HTML was used as the value (mchenryc, Kevin Glowacz) [#80]
0
 
0
 * Added ActionController::TestCase#rescue_action_in_public! to control whether the action under test should use the regular rescue_action path instead of simply raising the exception inline (great for error testing) [DHH]
...
283
284
285
286
 
287
288
289
...
283
284
285
 
286
287
288
289
0
@@ -283,7 +283,7 @@
0
       # # prefixed with 'payday' rather than 'date'
0
       # select_datetime(my_date_time, :prefix => 'payday')
0
       #
0
- def select_date(date = Date.today, options = {}, html_options = {})
0
+ def select_date(date = Date.current, options = {}, html_options = {})
0
         options[:order] ||= []
0
         [:year, :month, :day].each { |o| options[:order].push(o) unless options[:order].include?(o) }
0
 
...
950
951
952
 
 
 
 
 
 
 
 
 
953
954
955
...
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
0
@@ -950,6 +950,15 @@
0
       expects(:select_minute).with(time, anything, anything).returns('')
0
       select_time
0
     end
0
+
0
+ def test_select_date_uses_date_current_as_default
0
+ date = stub(:year => 2004, :month => 6, :day => 15)
0
+ Date.expects(:current).returns date
0
+ expects(:select_year).with(date, anything, anything).returns('')
0
+ expects(:select_month).with(date, anything, anything).returns('')
0
+ expects(:select_day).with(date, anything, anything).returns('')
0
+ select_date
0
+ end
0
   end
0
 
0
   def test_date_select
...
1
2
 
 
3
4
5
...
1
2
3
4
5
6
7
0
@@ -1,5 +1,7 @@
0
 *SVN*
0
 
0
+* Adding Date.current, which returns Time.zone.today if config.time_zone is set; otherwise returns Date.today [Geoff Buesing]
0
+
0
 * TimeWithZone: date part getter methods (#year #mon #day etc) are defined on class; no longer relying on method_missing [Geoff Buesing]
0
 
0
 * Time.zone.parse return nil for strings with no date information [Geoff Buesing]
...
25
26
27
 
 
 
 
 
28
29
30
...
25
26
27
28
29
30
31
32
33
34
35
0
@@ -25,6 +25,11 @@
0
           def tomorrow
0
             ::Date.today.tomorrow
0
           end
0
+
0
+ # Returns Time.zone.today when config.time_zone is set, otherwise just returns Date.today.
0
+ def current
0
+ ::Time.zone_default ? ::Time.zone.today : ::Date.today
0
+ end
0
         end
0
         
0
         # Converts Date to a Time (or DateTime if necessary) with the time portion set to the beginning of the day (0:00)
...
208
209
210
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
211
212
213
...
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
236
0
@@ -208,6 +208,29 @@
0
       end
0
     end
0
   end
0
+
0
+ uses_mocha 'TestDateCurrent' do
0
+ def test_current_returns_date_today_when_zone_default_not_set
0
+ with_env_tz 'US/Central' do
0
+ Time.stubs(:now).returns Time.local(1999, 12, 31, 23)
0
+ assert_equal Date.new(1999, 12, 31), Date.today
0
+ assert_equal Date.new(1999, 12, 31), Date.current
0
+ end
0
+ end
0
+
0
+ def test_current_returns_time_zone_today_when_zone_default_set
0
+ silence_warnings do # silence warnings raised by tzinfo gem
0
+ Time.zone_default = TimeZone['Eastern Time (US & Canada)']
0
+ with_env_tz 'US/Central' do
0
+ Time.stubs(:now).returns Time.local(1999, 12, 31, 23)
0
+ assert_equal Date.new(1999, 12, 31), Date.today
0
+ assert_equal Date.new(2000, 1, 1), Date.current
0
+ end
0
+ end
0
+ ensure
0
+ Time.zone_default = nil
0
+ end
0
+ end
0
 
0
   protected
0
     def with_env_tz(new_tz = 'US/Eastern')

Comments

    No one has commented yet.