Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
40bdf553
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,发现更多精彩内容 >>
提交
40bdf553
编写于
5月 18, 2012
作者:
J
Jeremy Kemper
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #6183 from nashby/fix-issue-6179
wrap time ranges with timezones
上级
8b4ecbeb
dcdde7da
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
65 addition
and
40 deletion
+65
-40
activesupport/lib/active_support/core_ext/time/calculations.rb
...esupport/lib/active_support/core_ext/time/calculations.rb
+4
-4
activesupport/lib/active_support/time_with_zone.rb
activesupport/lib/active_support/time_with_zone.rb
+12
-3
activesupport/test/core_ext/date_ext_test.rb
activesupport/test/core_ext/date_ext_test.rb
+2
-2
activesupport/test/core_ext/time_ext_test.rb
activesupport/test/core_ext/time_ext_test.rb
+39
-31
activesupport/test/core_ext/time_with_zone_test.rb
activesupport/test/core_ext/time_with_zone_test.rb
+8
-0
未找到文件。
activesupport/lib/active_support/core_ext/time/calculations.rb
浏览文件 @
40bdf553
...
...
@@ -253,7 +253,7 @@ def end_of_day
:hour
=>
23
,
:min
=>
59
,
:sec
=>
59
,
:usec
=>
999999.999
:usec
=>
Rational
(
999999999
,
1000
)
)
end
...
...
@@ -268,7 +268,7 @@ def end_of_hour
change
(
:min
=>
59
,
:sec
=>
59
,
:usec
=>
999999.999
:usec
=>
Rational
(
999999999
,
1000
)
)
end
...
...
@@ -288,7 +288,7 @@ def end_of_month
:hour
=>
23
,
:min
=>
59
,
:sec
=>
59
,
:usec
=>
999999.999
:usec
=>
Rational
(
999999999
,
1000
)
)
end
alias
:at_end_of_month
:end_of_month
...
...
@@ -321,7 +321,7 @@ def end_of_year
:hour
=>
23
,
:min
=>
59
,
:sec
=>
59
,
:usec
=>
999999.999
:usec
=>
Rational
(
999999999
,
1000
)
)
end
alias
:at_end_of_year
:end_of_year
...
...
activesupport/lib/active_support/time_with_zone.rb
浏览文件 @
40bdf553
...
...
@@ -317,8 +317,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
...
...
@@ -336,11 +335,21 @@ def get_period_and_ensure_valid_local_time
end
def
transfer_time_values_to_utc_constructor
(
time
)
::
Time
.
utc_time
(
time
.
year
,
time
.
month
,
time
.
day
,
time
.
hour
,
time
.
min
,
time
.
sec
,
time
.
respond_to?
(
:
usec
)
?
time
.
usec
:
0
)
::
Time
.
utc_time
(
time
.
year
,
time
.
month
,
time
.
day
,
time
.
hour
,
time
.
min
,
time
.
sec
,
time
.
respond_to?
(
:
nsec
)
?
Rational
(
time
.
nsec
,
1000
)
:
0
)
end
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/date_ext_test.rb
浏览文件 @
40bdf553
...
...
@@ -374,14 +374,14 @@ def test_beginning_of_day_when_zone_is_set
end
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
assert_equal
Time
.
local
(
2005
,
2
,
21
,
23
,
59
,
59
,
Rational
(
999999999
,
1000
)
),
Date
.
new
(
2005
,
2
,
21
).
end_of_day
end
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
assert_equal
zone
.
local
(
2005
,
2
,
21
,
23
,
59
,
59
,
999999.999
),
Date
.
new
(
2005
,
2
,
21
).
end_of_day
assert_equal
zone
.
local
(
2005
,
2
,
21
,
23
,
59
,
59
,
Rational
(
999999999
,
1000
)
),
Date
.
new
(
2005
,
2
,
21
).
end_of_day
assert_equal
zone
,
Date
.
new
(
2005
,
2
,
21
).
end_of_day
.
time_zone
end
end
...
...
activesupport/test/core_ext/time_ext_test.rb
浏览文件 @
40bdf553
...
...
@@ -109,49 +109,49 @@ def test_beginning_of_quarter
end
def
test_end_of_day
assert_equal
Time
.
local
(
2007
,
8
,
12
,
23
,
59
,
59
,
999999.999
),
Time
.
local
(
2007
,
8
,
12
,
10
,
10
,
10
).
end_of_day
assert_equal
Time
.
local
(
2007
,
8
,
12
,
23
,
59
,
59
,
Rational
(
999999999
,
1000
)
),
Time
.
local
(
2007
,
8
,
12
,
10
,
10
,
10
).
end_of_day
with_env_tz
'US/Eastern'
do
assert_equal
Time
.
local
(
2007
,
4
,
2
,
23
,
59
,
59
,
999999.999
),
Time
.
local
(
2007
,
4
,
2
,
10
,
10
,
10
).
end_of_day
,
'start DST'
assert_equal
Time
.
local
(
2007
,
10
,
29
,
23
,
59
,
59
,
999999.999
),
Time
.
local
(
2007
,
10
,
29
,
10
,
10
,
10
).
end_of_day
,
'ends DST'
assert_equal
Time
.
local
(
2007
,
4
,
2
,
23
,
59
,
59
,
Rational
(
999999999
,
1000
)
),
Time
.
local
(
2007
,
4
,
2
,
10
,
10
,
10
).
end_of_day
,
'start DST'
assert_equal
Time
.
local
(
2007
,
10
,
29
,
23
,
59
,
59
,
Rational
(
999999999
,
1000
)
),
Time
.
local
(
2007
,
10
,
29
,
10
,
10
,
10
).
end_of_day
,
'ends DST'
end
with_env_tz
'NZ'
do
assert_equal
Time
.
local
(
2006
,
3
,
19
,
23
,
59
,
59
,
999999.999
),
Time
.
local
(
2006
,
3
,
19
,
10
,
10
,
10
).
end_of_day
,
'ends DST'
assert_equal
Time
.
local
(
2006
,
10
,
1
,
23
,
59
,
59
,
999999.999
),
Time
.
local
(
2006
,
10
,
1
,
10
,
10
,
10
).
end_of_day
,
'start DST'
assert_equal
Time
.
local
(
2006
,
3
,
19
,
23
,
59
,
59
,
Rational
(
999999999
,
1000
)
),
Time
.
local
(
2006
,
3
,
19
,
10
,
10
,
10
).
end_of_day
,
'ends DST'
assert_equal
Time
.
local
(
2006
,
10
,
1
,
23
,
59
,
59
,
Rational
(
999999999
,
1000
)
),
Time
.
local
(
2006
,
10
,
1
,
10
,
10
,
10
).
end_of_day
,
'start DST'
end
end
def
test_end_of_week
assert_equal
Time
.
local
(
2008
,
1
,
6
,
23
,
59
,
59
,
999999.999
),
Time
.
local
(
2007
,
12
,
31
,
10
,
10
,
10
).
end_of_week
assert_equal
Time
.
local
(
2007
,
9
,
2
,
23
,
59
,
59
,
999999.999
),
Time
.
local
(
2007
,
8
,
27
,
0
,
0
,
0
).
end_of_week
#monday
assert_equal
Time
.
local
(
2007
,
9
,
2
,
23
,
59
,
59
,
999999.999
),
Time
.
local
(
2007
,
8
,
28
,
0
,
0
,
0
).
end_of_week
#tuesday
assert_equal
Time
.
local
(
2007
,
9
,
2
,
23
,
59
,
59
,
999999.999
),
Time
.
local
(
2007
,
8
,
29
,
0
,
0
,
0
).
end_of_week
#wednesday
assert_equal
Time
.
local
(
2007
,
9
,
2
,
23
,
59
,
59
,
999999.999
),
Time
.
local
(
2007
,
8
,
30
,
0
,
0
,
0
).
end_of_week
#thursday
assert_equal
Time
.
local
(
2007
,
9
,
2
,
23
,
59
,
59
,
999999.999
),
Time
.
local
(
2007
,
8
,
31
,
0
,
0
,
0
).
end_of_week
#friday
assert_equal
Time
.
local
(
2007
,
9
,
2
,
23
,
59
,
59
,
999999.999
),
Time
.
local
(
2007
,
9
,
01
,
0
,
0
,
0
).
end_of_week
#saturday
assert_equal
Time
.
local
(
2007
,
9
,
2
,
23
,
59
,
59
,
999999.999
),
Time
.
local
(
2007
,
9
,
02
,
0
,
0
,
0
).
end_of_week
#sunday
assert_equal
Time
.
local
(
2008
,
1
,
6
,
23
,
59
,
59
,
Rational
(
999999999
,
1000
)
),
Time
.
local
(
2007
,
12
,
31
,
10
,
10
,
10
).
end_of_week
assert_equal
Time
.
local
(
2007
,
9
,
2
,
23
,
59
,
59
,
Rational
(
999999999
,
1000
)
),
Time
.
local
(
2007
,
8
,
27
,
0
,
0
,
0
).
end_of_week
#monday
assert_equal
Time
.
local
(
2007
,
9
,
2
,
23
,
59
,
59
,
Rational
(
999999999
,
1000
)
),
Time
.
local
(
2007
,
8
,
28
,
0
,
0
,
0
).
end_of_week
#tuesday
assert_equal
Time
.
local
(
2007
,
9
,
2
,
23
,
59
,
59
,
Rational
(
999999999
,
1000
)
),
Time
.
local
(
2007
,
8
,
29
,
0
,
0
,
0
).
end_of_week
#wednesday
assert_equal
Time
.
local
(
2007
,
9
,
2
,
23
,
59
,
59
,
Rational
(
999999999
,
1000
)
),
Time
.
local
(
2007
,
8
,
30
,
0
,
0
,
0
).
end_of_week
#thursday
assert_equal
Time
.
local
(
2007
,
9
,
2
,
23
,
59
,
59
,
Rational
(
999999999
,
1000
)
),
Time
.
local
(
2007
,
8
,
31
,
0
,
0
,
0
).
end_of_week
#friday
assert_equal
Time
.
local
(
2007
,
9
,
2
,
23
,
59
,
59
,
Rational
(
999999999
,
1000
)
),
Time
.
local
(
2007
,
9
,
01
,
0
,
0
,
0
).
end_of_week
#saturday
assert_equal
Time
.
local
(
2007
,
9
,
2
,
23
,
59
,
59
,
Rational
(
999999999
,
1000
)
),
Time
.
local
(
2007
,
9
,
02
,
0
,
0
,
0
).
end_of_week
#sunday
end
def
test_end_of_hour
assert_equal
Time
.
local
(
2005
,
2
,
4
,
19
,
59
,
59
,
999999.999
),
Time
.
local
(
2005
,
2
,
4
,
19
,
30
,
10
).
end_of_hour
assert_equal
Time
.
local
(
2005
,
2
,
4
,
19
,
59
,
59
,
Rational
(
999999999
,
1000
)
),
Time
.
local
(
2005
,
2
,
4
,
19
,
30
,
10
).
end_of_hour
end
def
test_end_of_month
assert_equal
Time
.
local
(
2005
,
3
,
31
,
23
,
59
,
59
,
999999.999
),
Time
.
local
(
2005
,
3
,
20
,
10
,
10
,
10
).
end_of_month
assert_equal
Time
.
local
(
2005
,
2
,
28
,
23
,
59
,
59
,
999999.999
),
Time
.
local
(
2005
,
2
,
20
,
10
,
10
,
10
).
end_of_month
assert_equal
Time
.
local
(
2005
,
4
,
30
,
23
,
59
,
59
,
999999.999
),
Time
.
local
(
2005
,
4
,
20
,
10
,
10
,
10
).
end_of_month
assert_equal
Time
.
local
(
2005
,
3
,
31
,
23
,
59
,
59
,
Rational
(
999999999
,
1000
)
),
Time
.
local
(
2005
,
3
,
20
,
10
,
10
,
10
).
end_of_month
assert_equal
Time
.
local
(
2005
,
2
,
28
,
23
,
59
,
59
,
Rational
(
999999999
,
1000
)
),
Time
.
local
(
2005
,
2
,
20
,
10
,
10
,
10
).
end_of_month
assert_equal
Time
.
local
(
2005
,
4
,
30
,
23
,
59
,
59
,
Rational
(
999999999
,
1000
)
),
Time
.
local
(
2005
,
4
,
20
,
10
,
10
,
10
).
end_of_month
end
def
test_end_of_quarter
assert_equal
Time
.
local
(
2007
,
3
,
31
,
23
,
59
,
59
,
999999.999
),
Time
.
local
(
2007
,
2
,
15
,
10
,
10
,
10
).
end_of_quarter
assert_equal
Time
.
local
(
2007
,
3
,
31
,
23
,
59
,
59
,
999999.999
),
Time
.
local
(
2007
,
3
,
31
,
0
,
0
,
0
).
end_of_quarter
assert_equal
Time
.
local
(
2007
,
12
,
31
,
23
,
59
,
59
,
999999.999
),
Time
.
local
(
2007
,
12
,
21
,
10
,
10
,
10
).
end_of_quarter
assert_equal
Time
.
local
(
2007
,
6
,
30
,
23
,
59
,
59
,
999999.999
),
Time
.
local
(
2007
,
4
,
1
,
0
,
0
,
0
).
end_of_quarter
assert_equal
Time
.
local
(
2008
,
6
,
30
,
23
,
59
,
59
,
999999.999
),
Time
.
local
(
2008
,
5
,
31
,
0
,
0
,
0
).
end_of_quarter
assert_equal
Time
.
local
(
2007
,
3
,
31
,
23
,
59
,
59
,
Rational
(
999999999
,
1000
)
),
Time
.
local
(
2007
,
2
,
15
,
10
,
10
,
10
).
end_of_quarter
assert_equal
Time
.
local
(
2007
,
3
,
31
,
23
,
59
,
59
,
Rational
(
999999999
,
1000
)
),
Time
.
local
(
2007
,
3
,
31
,
0
,
0
,
0
).
end_of_quarter
assert_equal
Time
.
local
(
2007
,
12
,
31
,
23
,
59
,
59
,
Rational
(
999999999
,
1000
)
),
Time
.
local
(
2007
,
12
,
21
,
10
,
10
,
10
).
end_of_quarter
assert_equal
Time
.
local
(
2007
,
6
,
30
,
23
,
59
,
59
,
Rational
(
999999999
,
1000
)
),
Time
.
local
(
2007
,
4
,
1
,
0
,
0
,
0
).
end_of_quarter
assert_equal
Time
.
local
(
2008
,
6
,
30
,
23
,
59
,
59
,
Rational
(
999999999
,
1000
)
),
Time
.
local
(
2008
,
5
,
31
,
0
,
0
,
0
).
end_of_quarter
end
def
test_end_of_year
assert_equal
Time
.
local
(
2007
,
12
,
31
,
23
,
59
,
59
,
999999.999
),
Time
.
local
(
2007
,
2
,
22
,
10
,
10
,
10
).
end_of_year
assert_equal
Time
.
local
(
2007
,
12
,
31
,
23
,
59
,
59
,
999999.999
),
Time
.
local
(
2007
,
12
,
31
,
10
,
10
,
10
).
end_of_year
assert_equal
Time
.
local
(
2007
,
12
,
31
,
23
,
59
,
59
,
Rational
(
999999999
,
1000
)
),
Time
.
local
(
2007
,
2
,
22
,
10
,
10
,
10
).
end_of_year
assert_equal
Time
.
local
(
2007
,
12
,
31
,
23
,
59
,
59
,
Rational
(
999999999
,
1000
)
),
Time
.
local
(
2007
,
12
,
31
,
10
,
10
,
10
).
end_of_year
end
def
test_beginning_of_year
...
...
@@ -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
...
...
@@ -828,24 +828,32 @@ def test_case_equality
end
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
assert_equal
Time
.
local
(
2011
,
6
,
7
,
0
,
0
,
0
)
..
Time
.
local
(
2011
,
6
,
7
,
23
,
59
,
59
,
Rational
(
999999999
,
1000
)),
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
,
Rational
(
999999999
,
1000
)))
assert_equal
beginning_of_day
,
ActiveSupport
::
TimeWithZone
.
new
(
Time
.
local
(
2011
,
6
,
7
,
10
,
10
,
10
),
ActiveSupport
::
TimeZone
[
"Hawaii"
]).
all_day
.
begin
assert_equal
end_of_day
,
ActiveSupport
::
TimeWithZone
.
new
(
Time
.
local
(
2011
,
6
,
7
,
10
,
10
,
10
),
ActiveSupport
::
TimeZone
[
"Hawaii"
]).
all_day
.
end
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
)
assert_equal
Time
.
local
(
2011
,
6
,
6
,
0
,
0
,
0
)
..
Time
.
local
(
2011
,
6
,
12
,
23
,
59
,
59
,
Rational
(
999999999
,
1000
)
),
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
,
Rational
(
999999999
,
1000
)
),
Time
.
local
(
2011
,
6
,
7
,
10
,
10
,
10
).
all_week
(
:sunday
)
end
def
test_all_month
assert_equal
Time
.
local
(
2011
,
6
,
1
,
0
,
0
,
0
)
..
Time
.
local
(
2011
,
6
,
30
,
23
,
59
,
59
,
999999.999
),
Time
.
local
(
2011
,
6
,
7
,
10
,
10
,
10
).
all_month
assert_equal
Time
.
local
(
2011
,
6
,
1
,
0
,
0
,
0
)
..
Time
.
local
(
2011
,
6
,
30
,
23
,
59
,
59
,
Rational
(
999999999
,
1000
)
),
Time
.
local
(
2011
,
6
,
7
,
10
,
10
,
10
).
all_month
end
def
test_all_quarter
assert_equal
Time
.
local
(
2011
,
4
,
1
,
0
,
0
,
0
)
..
Time
.
local
(
2011
,
6
,
30
,
23
,
59
,
59
,
999999.999
),
Time
.
local
(
2011
,
6
,
7
,
10
,
10
,
10
).
all_quarter
assert_equal
Time
.
local
(
2011
,
4
,
1
,
0
,
0
,
0
)
..
Time
.
local
(
2011
,
6
,
30
,
23
,
59
,
59
,
Rational
(
999999999
,
1000
)
),
Time
.
local
(
2011
,
6
,
7
,
10
,
10
,
10
).
all_quarter
end
def
test_all_year
assert_equal
Time
.
local
(
2011
,
1
,
1
,
0
,
0
,
0
)
..
Time
.
local
(
2011
,
12
,
31
,
23
,
59
,
59
,
999999.999
),
Time
.
local
(
2011
,
6
,
7
,
10
,
10
,
10
).
all_year
assert_equal
Time
.
local
(
2011
,
1
,
1
,
0
,
0
,
0
)
..
Time
.
local
(
2011
,
12
,
31
,
23
,
59
,
59
,
Rational
(
999999999
,
1000
)
),
Time
.
local
(
2011
,
6
,
7
,
10
,
10
,
10
).
all_year
end
protected
...
...
activesupport/test/core_ext/time_with_zone_test.rb
浏览文件 @
40bdf553
...
...
@@ -80,6 +80,14 @@ def test_to_json_with_use_standard_json_time_format_config_set_to_true
ActiveSupport
.
use_standard_json_time_format
=
old
end
def
test_nsec
local
=
Time
.
local
(
2011
,
6
,
7
,
23
,
59
,
59
,
Rational
(
999999999
,
1000
))
with_zone
=
ActiveSupport
::
TimeWithZone
.
new
(
nil
,
ActiveSupport
::
TimeZone
[
"Hawaii"
],
local
)
assert_equal
local
.
nsec
,
with_zone
.
nsec
assert_equal
with_zone
.
nsec
,
999999999
end
def
test_strftime
assert_equal
'1999-12-31 19:00:00 EST -0500'
,
@twz
.
strftime
(
'%Y-%m-%d %H:%M:%S %Z %z'
)
end
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录