Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
0f8d2794
R
rails
项目概览
张重言
/
rails
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
rails
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
0f8d2794
编写于
2月 27, 2011
作者:
J
Josh Kalderimis
提交者:
Jeremy Kemper
2月 28, 2011
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
updated Time, Date and DateTime current methods in AS to use Time.zone and not Time.zone_default.
[#6410 state:committed]
上级
de971318
变更
10
显示空白变更内容
内联
并排
Showing
10 changed file
with
49 addition
and
47 deletion
+49
-47
actionpack/test/template/date_helper_test.rb
actionpack/test/template/date_helper_test.rb
+2
-2
activesupport/lib/active_support/core_ext/date/calculations.rb
...esupport/lib/active_support/core_ext/date/calculations.rb
+2
-2
activesupport/lib/active_support/core_ext/date/zones.rb
activesupport/lib/active_support/core_ext/date/zones.rb
+3
-3
activesupport/lib/active_support/core_ext/date_time/calculations.rb
...ort/lib/active_support/core_ext/date_time/calculations.rb
+2
-1
activesupport/lib/active_support/core_ext/time/calculations.rb
...esupport/lib/active_support/core_ext/time/calculations.rb
+2
-2
activesupport/test/core_ext/date_ext_test.rb
activesupport/test/core_ext/date_ext_test.rb
+16
-16
activesupport/test/core_ext/date_time_ext_test.rb
activesupport/test/core_ext/date_time_ext_test.rb
+4
-4
activesupport/test/core_ext/duration_test.rb
activesupport/test/core_ext/duration_test.rb
+5
-5
activesupport/test/core_ext/numeric_ext_test.rb
activesupport/test/core_ext/numeric_ext_test.rb
+5
-5
activesupport/test/core_ext/time_with_zone_test.rb
activesupport/test/core_ext/time_with_zone_test.rb
+8
-7
未找到文件。
actionpack/test/template/date_helper_test.rb
浏览文件 @
0f8d2794
...
...
@@ -1885,7 +1885,7 @@ def test_datetime_select_defaults_to_time_zone_now_when_config_time_zone_is_set
time
=
stub
(
:year
=>
2004
,
:month
=>
6
,
:day
=>
15
,
:hour
=>
16
,
:min
=>
35
,
:sec
=>
0
)
time_zone
=
mock
()
time_zone
.
expects
(
:now
).
returns
time
Time
.
zone
_default
=
time_zone
Time
.
zone
=
time_zone
@post
=
Post
.
new
expected
=
%{<select id="post_updated_at_1i" name="post[updated_at(1i)]">\n}
...
...
@@ -1912,7 +1912,7 @@ def test_datetime_select_defaults_to_time_zone_now_when_config_time_zone_is_set
assert_dom_equal
expected
,
datetime_select
(
"post"
,
"updated_at"
)
ensure
Time
.
zone
_default
=
nil
Time
.
zone
=
nil
end
def
test_datetime_select_with_html_options_within_fields_for
...
...
activesupport/lib/active_support/core_ext/date/calculations.rb
浏览文件 @
0f8d2794
...
...
@@ -36,9 +36,9 @@ def tomorrow
::
Date
.
current
.
tomorrow
end
# Returns Time.zone.today when
config.time_zone is
set, otherwise just returns Date.today.
# Returns Time.zone.today when
<tt>Time.zone</tt> or <tt>config.time_zone</tt> are
set, otherwise just returns Date.today.
def
current
::
Time
.
zone
_default
?
::
Time
.
zone
.
today
:
::
Date
.
today
::
Time
.
zone
?
::
Time
.
zone
.
today
:
::
Date
.
today
end
end
...
...
activesupport/lib/active_support/core_ext/date/zones.rb
浏览文件 @
0f8d2794
...
...
@@ -2,10 +2,10 @@
require
'active_support/core_ext/time/zones'
class
Date
# Converts Date to a TimeWithZone in the current zone if Time.zone
_default is set,
# otherwise converts Date to a Time via Date#to_time
# Converts Date to a TimeWithZone in the current zone if Time.zone
or Time.zone_default
#
is set,
otherwise converts Date to a Time via Date#to_time
def
to_time_in_current_zone
if
::
Time
.
zone
_default
if
::
Time
.
zone
::
Time
.
zone
.
local
(
year
,
month
,
day
)
else
to_time
...
...
activesupport/lib/active_support/core_ext/date_time/calculations.rb
浏览文件 @
0f8d2794
...
...
@@ -9,8 +9,9 @@ def local_offset
::
Time
.
local
(
2007
).
utc_offset
.
to_r
/
86400
end
# Returns <tt>Time.zone.now.to_datetime</tt> when <tt>Time.zone</tt> or <tt>config.time_zone</tt> are set, otherwise returns <tt>Time.now.to_datetime</tt>.
def
current
::
Time
.
zone
_default
?
::
Time
.
zone
.
now
.
to_datetime
:
::
Time
.
now
.
to_datetime
::
Time
.
zone
?
::
Time
.
zone
.
now
.
to_datetime
:
::
Time
.
now
.
to_datetime
end
end
...
...
activesupport/lib/active_support/core_ext/time/calculations.rb
浏览文件 @
0f8d2794
...
...
@@ -41,9 +41,9 @@ def local_time(*args)
time_with_datetime_fallback
(
:local
,
*
args
)
end
# Returns <tt>Time.zone.now</tt> when <tt>
config.time_zone</tt> is
set, otherwise just returns <tt>Time.now</tt>.
# Returns <tt>Time.zone.now</tt> when <tt>
Time.zone</tt> or <tt>config.time_zone</tt> are
set, otherwise just returns <tt>Time.now</tt>.
def
current
::
Time
.
zone
_default
?
::
Time
.
zone
.
now
:
::
Time
.
now
::
Time
.
zone
?
::
Time
.
zone
.
now
:
::
Time
.
now
end
end
...
...
activesupport/test/core_ext/date_ext_test.rb
浏览文件 @
0f8d2794
...
...
@@ -259,7 +259,7 @@ def test_yesterday_constructor
assert_equal
Date
.
current
-
1
,
Date
.
yesterday
end
def
test_yesterday_constructor_when_zone_
default_
is_not_set
def
test_yesterday_constructor_when_zone_is_not_set
with_env_tz
'UTC'
do
with_tz_default
do
Time
.
stubs
(
:now
).
returns
Time
.
local
(
2000
,
1
,
1
)
...
...
@@ -268,7 +268,7 @@ def test_yesterday_constructor_when_zone_default_is_not_set
end
end
def
test_yesterday_constructor_when_zone_
default_
is_set
def
test_yesterday_constructor_when_zone_is_set
with_env_tz
'UTC'
do
with_tz_default
ActiveSupport
::
TimeZone
[
'Eastern Time (US & Canada)'
]
do
# UTC -5
Time
.
stubs
(
:now
).
returns
Time
.
local
(
2000
,
1
,
1
)
...
...
@@ -281,7 +281,7 @@ def test_tomorrow_constructor
assert_equal
Date
.
current
+
1
,
Date
.
tomorrow
end
def
test_tomorrow_constructor_when_zone_
default_
is_not_set
def
test_tomorrow_constructor_when_zone_is_not_set
with_env_tz
'UTC'
do
with_tz_default
do
Time
.
stubs
(
:now
).
returns
Time
.
local
(
1999
,
12
,
31
)
...
...
@@ -290,7 +290,7 @@ def test_tomorrow_constructor_when_zone_default_is_not_set
end
end
def
test_tomorrow_constructor_when_zone_
default_
is_set
def
test_tomorrow_constructor_when_zone_is_set
with_env_tz
'UTC'
do
with_tz_default
ActiveSupport
::
TimeZone
[
'Europe/Paris'
]
do
# UTC +1
Time
.
stubs
(
:now
).
returns
Time
.
local
(
1999
,
12
,
31
,
23
)
...
...
@@ -303,7 +303,7 @@ def test_since
assert_equal
Time
.
local
(
2005
,
2
,
21
,
0
,
0
,
45
),
Date
.
new
(
2005
,
2
,
21
).
since
(
45
)
end
def
test_since_when_zone_
default_
is_set
def
test_since_when_zone_is_set
zone
=
ActiveSupport
::
TimeZone
[
'Eastern Time (US & Canada)'
]
with_env_tz
'UTC'
do
with_tz_default
zone
do
...
...
@@ -317,7 +317,7 @@ def test_ago
assert_equal
Time
.
local
(
2005
,
2
,
20
,
23
,
59
,
15
),
Date
.
new
(
2005
,
2
,
21
).
ago
(
45
)
end
def
test_ago_when_zone_
default_
is_set
def
test_ago_when_zone_is_set
zone
=
ActiveSupport
::
TimeZone
[
'Eastern Time (US & Canada)'
]
with_env_tz
'UTC'
do
with_tz_default
zone
do
...
...
@@ -331,7 +331,7 @@ def test_beginning_of_day
assert_equal
Time
.
local
(
2005
,
2
,
21
,
0
,
0
,
0
),
Date
.
new
(
2005
,
2
,
21
).
beginning_of_day
end
def
test_beginning_of_day_when_zone_
default_
is_set
def
test_beginning_of_day_when_zone_is_set
zone
=
ActiveSupport
::
TimeZone
[
'Eastern Time (US & Canada)'
]
with_env_tz
'UTC'
do
with_tz_default
zone
do
...
...
@@ -345,7 +345,7 @@ def test_end_of_day
assert_equal
Time
.
local
(
2005
,
2
,
21
,
23
,
59
,
59
,
999999.999
),
Date
.
new
(
2005
,
2
,
21
).
end_of_day
end
def
test_end_of_day_when_zone_
default_
is_set
def
test_end_of_day_when_zone_is_set
zone
=
ActiveSupport
::
TimeZone
[
'Eastern Time (US & Canada)'
]
with_env_tz
'UTC'
do
with_tz_default
zone
do
...
...
@@ -367,7 +367,7 @@ def test_xmlschema
end
end
def
test_xmlschema_when_zone_
default_
is_set
def
test_xmlschema_when_zone_is_set
with_env_tz
'UTC'
do
with_tz_default
ActiveSupport
::
TimeZone
[
'Eastern Time (US & Canada)'
]
do
# UTC -5
assert_match
(
/^1980-02-28T00:00:00-05:?00$/
,
Date
.
new
(
1980
,
2
,
28
).
xmlschema
)
...
...
@@ -407,7 +407,7 @@ def test_future
assert_equal
true
,
Date
.
new
(
2000
,
1
,
2
).
future?
end
def
test_current_returns_date_today_when_zone_
default_
not_set
def
test_current_returns_date_today_when_zone_not_set
with_env_tz
'US/Central'
do
Time
.
stubs
(
:now
).
returns
Time
.
local
(
1999
,
12
,
31
,
23
)
assert_equal
Date
.
new
(
1999
,
12
,
31
),
Date
.
today
...
...
@@ -415,15 +415,15 @@ def test_current_returns_date_today_when_zone_default_not_set
end
end
def
test_current_returns_time_zone_today_when_zone_
default
_set
Time
.
zone
_default
=
ActiveSupport
::
TimeZone
[
'Eastern Time (US & Canada)'
]
def
test_current_returns_time_zone_today_when_zone_
is
_set
Time
.
zone
=
ActiveSupport
::
TimeZone
[
'Eastern Time (US & Canada)'
]
with_env_tz
'US/Central'
do
Time
.
stubs
(
:now
).
returns
Time
.
local
(
1999
,
12
,
31
,
23
)
assert_equal
Date
.
new
(
1999
,
12
,
31
),
Date
.
today
assert_equal
Date
.
new
(
2000
,
1
,
1
),
Date
.
current
end
ensure
Time
.
zone
_default
=
nil
Time
.
zone
=
nil
end
def
test_date_advance_should_not_change_passed_options_hash
...
...
@@ -441,11 +441,11 @@ def with_env_tz(new_tz = 'US/Eastern')
end
def
with_tz_default
(
tz
=
nil
)
old_tz
=
Time
.
zone
_default
Time
.
zone
_default
=
tz
old_tz
=
Time
.
zone
Time
.
zone
=
tz
yield
ensure
Time
.
zone
_default
=
old_tz
Time
.
zone
=
old_tz
end
end
...
...
activesupport/test/core_ext/date_time_ext_test.rb
浏览文件 @
0f8d2794
...
...
@@ -282,21 +282,21 @@ def test_future_without_offset
assert_equal
true
,
DateTime
.
civil
(
2005
,
2
,
10
,
20
,
30
,
46
).
future?
end
def
test_current_returns_date_today_when_zone_
default
_not_set
def
test_current_returns_date_today_when_zone_
is
_not_set
with_env_tz
'US/Eastern'
do
Time
.
stubs
(
:now
).
returns
Time
.
local
(
1999
,
12
,
31
,
23
,
59
,
59
)
assert_equal
DateTime
.
new
(
1999
,
12
,
31
,
23
,
59
,
59
,
Rational
(
-
18000
,
86400
)),
DateTime
.
current
end
end
def
test_current_returns_time_zone_today_when_zone_
default
_set
Time
.
zone
_default
=
ActiveSupport
::
TimeZone
[
'Eastern Time (US & Canada)'
]
def
test_current_returns_time_zone_today_when_zone_
is
_set
Time
.
zone
=
ActiveSupport
::
TimeZone
[
'Eastern Time (US & Canada)'
]
with_env_tz
'US/Eastern'
do
Time
.
stubs
(
:now
).
returns
Time
.
local
(
1999
,
12
,
31
,
23
,
59
,
59
)
assert_equal
DateTime
.
new
(
1999
,
12
,
31
,
23
,
59
,
59
,
Rational
(
-
18000
,
86400
)),
DateTime
.
current
end
ensure
Time
.
zone
_default
=
nil
Time
.
zone
=
nil
end
def
test_current_without_time_zone
...
...
activesupport/test/core_ext/duration_test.rb
浏览文件 @
0f8d2794
...
...
@@ -89,8 +89,8 @@ def test_since_and_ago_with_fractional_weeks
assert_in_delta
((
7
*
24
*
1.7
).
hours
.
ago
(
t
),
1.7
.
weeks
.
ago
(
t
),
1
)
end
def
test_since_and_ago_anchored_to_time_now_when_time_zone_
default
_not_set
Time
.
zone
_default
=
nil
def
test_since_and_ago_anchored_to_time_now_when_time_zone_
is
_not_set
Time
.
zone
=
nil
with_env_tz
'US/Eastern'
do
Time
.
stubs
(
:now
).
returns
Time
.
local
(
2000
)
# since
...
...
@@ -102,8 +102,8 @@ def test_since_and_ago_anchored_to_time_now_when_time_zone_default_not_set
end
end
def
test_since_and_ago_anchored_to_time_zone_now_when_time_zone_
default
_set
Time
.
zone
_default
=
ActiveSupport
::
TimeZone
[
'Eastern Time (US & Canada)'
]
def
test_since_and_ago_anchored_to_time_zone_now_when_time_zone_
is
_set
Time
.
zone
=
ActiveSupport
::
TimeZone
[
'Eastern Time (US & Canada)'
]
with_env_tz
'US/Eastern'
do
Time
.
stubs
(
:now
).
returns
Time
.
local
(
2000
)
# since
...
...
@@ -116,7 +116,7 @@ def test_since_and_ago_anchored_to_time_zone_now_when_time_zone_default_set
assert_equal
'Eastern Time (US & Canada)'
,
5
.
seconds
.
ago
.
time_zone
.
name
end
ensure
Time
.
zone
_default
=
nil
Time
.
zone
=
nil
end
def
test_adding_hours_across_dst_boundary
...
...
activesupport/test/core_ext/numeric_ext_test.rb
浏览文件 @
0f8d2794
...
...
@@ -89,8 +89,8 @@ def test_add_one_year_to_leap_day
assert_equal
DateTime
.
civil
(
2005
,
2
,
28
,
15
,
15
,
10
),
DateTime
.
civil
(
2004
,
2
,
29
,
15
,
15
,
10
)
+
1
.
year
end
def
test_since_and_ago_anchored_to_time_now_when_time_zone_
default
_not_set
Time
.
zone
_default
=
nil
def
test_since_and_ago_anchored_to_time_now_when_time_zone_
is
_not_set
Time
.
zone
=
nil
with_env_tz
'US/Eastern'
do
Time
.
stubs
(
:now
).
returns
Time
.
local
(
2000
)
# since
...
...
@@ -102,8 +102,8 @@ def test_since_and_ago_anchored_to_time_now_when_time_zone_default_not_set
end
end
def
test_since_and_ago_anchored_to_time_zone_now_when_time_zone_
default
_set
Time
.
zone
_default
=
ActiveSupport
::
TimeZone
[
'Eastern Time (US & Canada)'
]
def
test_since_and_ago_anchored_to_time_zone_now_when_time_zone_
is
_set
Time
.
zone
=
ActiveSupport
::
TimeZone
[
'Eastern Time (US & Canada)'
]
with_env_tz
'US/Eastern'
do
Time
.
stubs
(
:now
).
returns
Time
.
local
(
2000
)
# since
...
...
@@ -116,7 +116,7 @@ def test_since_and_ago_anchored_to_time_zone_now_when_time_zone_default_set
assert_equal
'Eastern Time (US & Canada)'
,
5
.
ago
.
time_zone
.
name
end
ensure
Time
.
zone
_default
=
nil
Time
.
zone
=
nil
end
protected
...
...
activesupport/test/core_ext/time_with_zone_test.rb
浏览文件 @
0f8d2794
...
...
@@ -768,10 +768,10 @@ def test_in_time_zone_with_time_local_instance
end
def
test_localtime
Time
.
zone
_default
=
ActiveSupport
::
TimeZone
[
'Eastern Time (US & Canada)'
]
Time
.
zone
=
ActiveSupport
::
TimeZone
[
'Eastern Time (US & Canada)'
]
assert_equal
@dt
.
in_time_zone
.
localtime
,
@dt
.
in_time_zone
.
utc
.
to_time
.
getlocal
ensure
Time
.
zone
_default
=
nil
Time
.
zone
=
nil
end
def
test_use_zone
...
...
@@ -801,7 +801,7 @@ def test_time_zone_getter_and_setter
assert_equal
nil
,
Time
.
zone
end
def
test_time_zone_getter_and_setter_with_zone_default
def
test_time_zone_getter_and_setter_with_zone_default
_set
Time
.
zone_default
=
ActiveSupport
::
TimeZone
[
'Alaska'
]
assert_equal
ActiveSupport
::
TimeZone
[
'Alaska'
],
Time
.
zone
Time
.
zone
=
ActiveSupport
::
TimeZone
[
'Hawaii'
]
...
...
@@ -809,6 +809,7 @@ def test_time_zone_getter_and_setter_with_zone_default
Time
.
zone
=
nil
assert_equal
ActiveSupport
::
TimeZone
[
'Alaska'
],
Time
.
zone
ensure
Time
.
zone
=
nil
Time
.
zone_default
=
nil
end
...
...
@@ -849,7 +850,7 @@ def test_time_zone_setter_with_invalid_zone
assert_nil
Time
.
zone
end
def
test_current_returns_time_now_when_zone_
default_
not_set
def
test_current_returns_time_now_when_zone_not_set
with_env_tz
'US/Eastern'
do
Time
.
stubs
(
:now
).
returns
Time
.
local
(
2000
)
assert_equal
false
,
Time
.
current
.
is_a?
(
ActiveSupport
::
TimeWithZone
)
...
...
@@ -857,8 +858,8 @@ def test_current_returns_time_now_when_zone_default_not_set
end
end
def
test_current_returns_time_zone_now_when_zone_
default_
set
Time
.
zone
_default
=
ActiveSupport
::
TimeZone
[
'Eastern Time (US & Canada)'
]
def
test_current_returns_time_zone_now_when_zone_set
Time
.
zone
=
ActiveSupport
::
TimeZone
[
'Eastern Time (US & Canada)'
]
with_env_tz
'US/Eastern'
do
Time
.
stubs
(
:now
).
returns
Time
.
local
(
2000
)
assert_equal
true
,
Time
.
current
.
is_a?
(
ActiveSupport
::
TimeWithZone
)
...
...
@@ -866,7 +867,7 @@ def test_current_returns_time_zone_now_when_zone_default_set
assert_equal
Time
.
utc
(
2000
),
Time
.
current
.
time
end
ensure
Time
.
zone
_default
=
nil
Time
.
zone
=
nil
end
protected
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录