Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
e2e51362
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,发现更多精彩内容 >>
提交
e2e51362
编写于
5月 06, 2012
作者:
V
Vasiliy Ermolovich
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
wrap time ranges with timezones, closes #6179
上级
a29bc1cf
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
20 addition
and
3 deletion
+20
-3
activesupport/lib/active_support/time_with_zone.rb
activesupport/lib/active_support/time_with_zone.rb
+11
-2
activesupport/test/core_ext/time_ext_test.rb
activesupport/test/core_ext/time_ext_test.rb
+9
-1
未找到文件。
activesupport/lib/active_support/time_with_zone.rb
浏览文件 @
e2e51362
...
...
@@ -319,8 +319,7 @@ def respond_to_missing?(sym, include_priv)
# Send the missing method to +time+ instance, and wrap result in a new TimeWithZone with the existing +time_zone+.
def
method_missing
(
sym
,
*
args
,
&
block
)
result
=
time
.
__send__
(
sym
,
*
args
,
&
block
)
result
.
acts_like?
(
:time
)
?
self
.
class
.
new
(
nil
,
time_zone
,
result
)
:
result
wrap_with_time_zone
time
.
__send__
(
sym
,
*
args
,
&
block
)
end
private
...
...
@@ -344,5 +343,15 @@ def transfer_time_values_to_utc_constructor(time)
def
duration_of_variable_length?
(
obj
)
ActiveSupport
::
Duration
===
obj
&&
obj
.
parts
.
any?
{
|
p
|
p
[
0
].
in?
([
:years
,
:months
,
:days
])
}
end
def
wrap_with_time_zone
(
time
)
if
time
.
acts_like?
(
:time
)
self
.
class
.
new
(
nil
,
time_zone
,
time
)
elsif
time
.
is_a?
(
Range
)
wrap_with_time_zone
(
time
.
begin
)
..
wrap_with_time_zone
(
time
.
end
)
else
time
end
end
end
end
activesupport/test/core_ext/time_ext_test.rb
浏览文件 @
e2e51362
...
...
@@ -517,7 +517,7 @@ def test_prev_week
assert_equal
Time
.
local
(
2006
,
11
,
15
),
Time
.
local
(
2006
,
11
,
23
,
0
,
0
,
0
).
prev_week
(
:wednesday
)
end
end
def
test_last_week
with_env_tz
'US/Eastern'
do
assert_equal
Time
.
local
(
2005
,
2
,
21
),
Time
.
local
(
2005
,
3
,
1
,
15
,
15
,
10
).
last_week
...
...
@@ -831,6 +831,14 @@ def test_all_day
assert_equal
Time
.
local
(
2011
,
6
,
7
,
0
,
0
,
0
)
..
Time
.
local
(
2011
,
6
,
7
,
23
,
59
,
59
,
999999.999
),
Time
.
local
(
2011
,
6
,
7
,
10
,
10
,
10
).
all_day
end
def
test_all_day_with_timezone
beginning_of_day
=
ActiveSupport
::
TimeWithZone
.
new
(
nil
,
ActiveSupport
::
TimeZone
[
"Hawaii"
],
Time
.
local
(
2011
,
6
,
7
,
0
,
0
,
0
))
end_of_day
=
ActiveSupport
::
TimeWithZone
.
new
(
nil
,
ActiveSupport
::
TimeZone
[
"Hawaii"
],
Time
.
local
(
2011
,
6
,
7
,
23
,
59
,
59
,
999999.999
))
assert_equal
beginning_of_day
.
inspect
,
ActiveSupport
::
TimeWithZone
.
new
(
Time
.
local
(
2011
,
6
,
7
,
10
,
10
,
10
),
ActiveSupport
::
TimeZone
[
"Hawaii"
]).
all_day
.
begin
.
inspect
assert_equal
end_of_day
.
inspect
,
ActiveSupport
::
TimeWithZone
.
new
(
Time
.
local
(
2011
,
6
,
7
,
10
,
10
,
10
),
ActiveSupport
::
TimeZone
[
"Hawaii"
]).
all_day
.
end
.
inspect
end
def
test_all_week
assert_equal
Time
.
local
(
2011
,
6
,
6
,
0
,
0
,
0
)
..
Time
.
local
(
2011
,
6
,
12
,
23
,
59
,
59
,
999999.999
),
Time
.
local
(
2011
,
6
,
7
,
10
,
10
,
10
).
all_week
assert_equal
Time
.
local
(
2011
,
6
,
5
,
0
,
0
,
0
)
..
Time
.
local
(
2011
,
6
,
11
,
23
,
59
,
59
,
999999.999
),
Time
.
local
(
2011
,
6
,
7
,
10
,
10
,
10
).
all_week
(
:sunday
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录