Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
bb3bc475
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,发现更多精彩内容 >>
提交
bb3bc475
编写于
9月 24, 2016
作者:
A
Andrew White
提交者:
GitHub
9月 24, 2016
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #26597 from tbalthazar/26580
Fix ActiveSupport::TimeWithZone#in
上级
0ce117fa
76c2553b
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
51 addition
and
1 deletion
+51
-1
activesupport/CHANGELOG.md
activesupport/CHANGELOG.md
+19
-0
activesupport/lib/active_support/time_with_zone.rb
activesupport/lib/active_support/time_with_zone.rb
+1
-0
activesupport/test/core_ext/time_with_zone_test.rb
activesupport/test/core_ext/time_with_zone_test.rb
+31
-1
未找到文件。
activesupport/CHANGELOG.md
浏览文件 @
bb3bc475
*
Fix
`ActiveSupport::TimeWithZone#in`
across DST boundaries.
Previously calls to `in` were being sent to the non-DST aware
method `Time#since` via `method_missing`. It is now aliased to
the DST aware `ActiveSupport::TimeWithZone#+` which handles
transitions across DST boundaries, e.g:
Time.zone = "US/Eastern"
t = Time.zone.local(2016,11,6,1)
# => Sun, 06 Nov 2016 01:00:00 EDT -05:00
t.in(1.hour)
# => Sun, 06 Nov 2016 01:00:00 EST -05:00
Fixes #26580.
*Thomas Balthazar*
*
Remove unused parameter
`options = nil`
for
`#clear`
of
`ActiveSupport::Cache::Strategy::LocalCache::LocalStore`
and
`ActiveSupport::Cache::Strategy::LocalCache`
.
...
...
activesupport/lib/active_support/time_with_zone.rb
浏览文件 @
bb3bc475
...
...
@@ -279,6 +279,7 @@ def +(other)
end
end
alias_method
:since
,
:
+
alias_method
:in
,
:
+
# Returns a new TimeWithZone object that represents the difference between
# the current object's time and the +other+ time.
...
...
activesupport/test/core_ext/time_with_zone_test.rb
浏览文件 @
bb3bc475
...
...
@@ -675,6 +675,10 @@ def test_since
assert_equal
"Fri, 31 Dec 1999 19:00:01 EST -05:00"
,
@twz
.
since
(
1
).
inspect
end
def
test_in
assert_equal
"Fri, 31 Dec 1999 19:00:01 EST -05:00"
,
@twz
.
in
(
1
).
inspect
end
def
test_ago
assert_equal
"Fri, 31 Dec 1999 18:59:59 EST -05:00"
,
@twz
.
ago
(
1
).
inspect
end
...
...
@@ -688,6 +692,7 @@ def test_advance_1_year_from_leap_day
assert_equal
"Mon, 28 Feb 2005 00:00:00 EST -05:00"
,
twz
.
advance
(
years:
1
).
inspect
assert_equal
"Mon, 28 Feb 2005 00:00:00 EST -05:00"
,
twz
.
years_since
(
1
).
inspect
assert_equal
"Mon, 28 Feb 2005 00:00:00 EST -05:00"
,
twz
.
since
(
1
.
year
).
inspect
assert_equal
"Mon, 28 Feb 2005 00:00:00 EST -05:00"
,
twz
.
in
(
1
.
year
).
inspect
assert_equal
"Mon, 28 Feb 2005 00:00:00 EST -05:00"
,
(
twz
+
1
.
year
).
inspect
end
...
...
@@ -696,6 +701,7 @@ def test_advance_1_month_from_last_day_of_january
assert_equal
"Mon, 28 Feb 2005 00:00:00 EST -05:00"
,
twz
.
advance
(
months:
1
).
inspect
assert_equal
"Mon, 28 Feb 2005 00:00:00 EST -05:00"
,
twz
.
months_since
(
1
).
inspect
assert_equal
"Mon, 28 Feb 2005 00:00:00 EST -05:00"
,
twz
.
since
(
1
.
month
).
inspect
assert_equal
"Mon, 28 Feb 2005 00:00:00 EST -05:00"
,
twz
.
in
(
1
.
month
).
inspect
assert_equal
"Mon, 28 Feb 2005 00:00:00 EST -05:00"
,
(
twz
+
1
.
month
).
inspect
end
...
...
@@ -704,6 +710,7 @@ def test_advance_1_month_from_last_day_of_january_during_leap_year
assert_equal
"Tue, 29 Feb 2000 00:00:00 EST -05:00"
,
twz
.
advance
(
months:
1
).
inspect
assert_equal
"Tue, 29 Feb 2000 00:00:00 EST -05:00"
,
twz
.
months_since
(
1
).
inspect
assert_equal
"Tue, 29 Feb 2000 00:00:00 EST -05:00"
,
twz
.
since
(
1
.
month
).
inspect
assert_equal
"Tue, 29 Feb 2000 00:00:00 EST -05:00"
,
twz
.
in
(
1
.
month
).
inspect
assert_equal
"Tue, 29 Feb 2000 00:00:00 EST -05:00"
,
(
twz
+
1
.
month
).
inspect
end
...
...
@@ -712,6 +719,7 @@ def test_advance_1_month_into_spring_dst_gap
assert_equal
"Sun, 02 Apr 2006 03:00:00 EDT -04:00"
,
twz
.
advance
(
months:
1
).
inspect
assert_equal
"Sun, 02 Apr 2006 03:00:00 EDT -04:00"
,
twz
.
months_since
(
1
).
inspect
assert_equal
"Sun, 02 Apr 2006 03:00:00 EDT -04:00"
,
twz
.
since
(
1
.
month
).
inspect
assert_equal
"Sun, 02 Apr 2006 03:00:00 EDT -04:00"
,
twz
.
in
(
1
.
month
).
inspect
assert_equal
"Sun, 02 Apr 2006 03:00:00 EDT -04:00"
,
(
twz
+
1
.
month
).
inspect
end
...
...
@@ -719,9 +727,11 @@ def test_advance_1_second_into_spring_dst_gap
twz
=
ActiveSupport
::
TimeWithZone
.
new
(
nil
,
@time_zone
,
Time
.
utc
(
2006
,
4
,
2
,
1
,
59
,
59
))
assert_equal
"Sun, 02 Apr 2006 03:00:00 EDT -04:00"
,
twz
.
advance
(
seconds:
1
).
inspect
assert_equal
"Sun, 02 Apr 2006 03:00:00 EDT -04:00"
,
(
twz
+
1
).
inspect
assert_equal
"Sun, 02 Apr 2006 03:00:00 EDT -04:00"
,
(
twz
+
1
.
second
).
inspect
assert_equal
"Sun, 02 Apr 2006 03:00:00 EDT -04:00"
,
twz
.
since
(
1
).
inspect
assert_equal
"Sun, 02 Apr 2006 03:00:00 EDT -04:00"
,
twz
.
since
(
1
.
second
).
inspect
assert_equal
"Sun, 02 Apr 2006 03:00:00 EDT -04:00"
,
(
twz
+
1
.
second
).
inspect
assert_equal
"Sun, 02 Apr 2006 03:00:00 EDT -04:00"
,
twz
.
in
(
1
).
inspect
assert_equal
"Sun, 02 Apr 2006 03:00:00 EDT -04:00"
,
twz
.
in
(
1
.
second
).
inspect
end
def
test_advance_1_day_across_spring_dst_transition
...
...
@@ -730,8 +740,10 @@ def test_advance_1_day_across_spring_dst_transition
# When we advance 1 day, we want to end up at the same time on the next day
assert_equal
"Sun, 02 Apr 2006 10:30:00 EDT -04:00"
,
twz
.
advance
(
days:
1
).
inspect
assert_equal
"Sun, 02 Apr 2006 10:30:00 EDT -04:00"
,
twz
.
since
(
1
.
days
).
inspect
assert_equal
"Sun, 02 Apr 2006 10:30:00 EDT -04:00"
,
twz
.
in
(
1
.
days
).
inspect
assert_equal
"Sun, 02 Apr 2006 10:30:00 EDT -04:00"
,
(
twz
+
1
.
days
).
inspect
assert_equal
"Sun, 02 Apr 2006 10:30:01 EDT -04:00"
,
twz
.
since
(
1
.
days
+
1
.
second
).
inspect
assert_equal
"Sun, 02 Apr 2006 10:30:01 EDT -04:00"
,
twz
.
in
(
1
.
days
+
1
.
second
).
inspect
assert_equal
"Sun, 02 Apr 2006 10:30:01 EDT -04:00"
,
(
twz
+
1
.
days
+
1
.
second
).
inspect
end
...
...
@@ -753,12 +765,16 @@ def test_advance_1_day_expressed_as_number_of_seconds_minutes_or_hours_across_sp
assert_equal
"Sun, 02 Apr 2006 11:30:00 EDT -04:00"
,
(
twz
+
86400
.
seconds
).
inspect
assert_equal
"Sun, 02 Apr 2006 11:30:00 EDT -04:00"
,
twz
.
since
(
86400
).
inspect
assert_equal
"Sun, 02 Apr 2006 11:30:00 EDT -04:00"
,
twz
.
since
(
86400
.
seconds
).
inspect
assert_equal
"Sun, 02 Apr 2006 11:30:00 EDT -04:00"
,
twz
.
in
(
86400
).
inspect
assert_equal
"Sun, 02 Apr 2006 11:30:00 EDT -04:00"
,
twz
.
in
(
86400
.
seconds
).
inspect
assert_equal
"Sun, 02 Apr 2006 11:30:00 EDT -04:00"
,
twz
.
advance
(
seconds:
86400
).
inspect
assert_equal
"Sun, 02 Apr 2006 11:30:00 EDT -04:00"
,
(
twz
+
1440
.
minutes
).
inspect
assert_equal
"Sun, 02 Apr 2006 11:30:00 EDT -04:00"
,
twz
.
since
(
1440
.
minutes
).
inspect
assert_equal
"Sun, 02 Apr 2006 11:30:00 EDT -04:00"
,
twz
.
in
(
1440
.
minutes
).
inspect
assert_equal
"Sun, 02 Apr 2006 11:30:00 EDT -04:00"
,
twz
.
advance
(
minutes:
1440
).
inspect
assert_equal
"Sun, 02 Apr 2006 11:30:00 EDT -04:00"
,
(
twz
+
24
.
hours
).
inspect
assert_equal
"Sun, 02 Apr 2006 11:30:00 EDT -04:00"
,
twz
.
since
(
24
.
hours
).
inspect
assert_equal
"Sun, 02 Apr 2006 11:30:00 EDT -04:00"
,
twz
.
in
(
24
.
hours
).
inspect
assert_equal
"Sun, 02 Apr 2006 11:30:00 EDT -04:00"
,
twz
.
advance
(
hours:
24
).
inspect
end
...
...
@@ -785,8 +801,10 @@ def test_advance_1_day_across_fall_dst_transition
# When we advance 1 day, we want to end up at the same time on the next day
assert_equal
"Sun, 29 Oct 2006 10:30:00 EST -05:00"
,
twz
.
advance
(
days:
1
).
inspect
assert_equal
"Sun, 29 Oct 2006 10:30:00 EST -05:00"
,
twz
.
since
(
1
.
days
).
inspect
assert_equal
"Sun, 29 Oct 2006 10:30:00 EST -05:00"
,
twz
.
in
(
1
.
days
).
inspect
assert_equal
"Sun, 29 Oct 2006 10:30:00 EST -05:00"
,
(
twz
+
1
.
days
).
inspect
assert_equal
"Sun, 29 Oct 2006 10:30:01 EST -05:00"
,
twz
.
since
(
1
.
days
+
1
.
second
).
inspect
assert_equal
"Sun, 29 Oct 2006 10:30:01 EST -05:00"
,
twz
.
in
(
1
.
days
+
1
.
second
).
inspect
assert_equal
"Sun, 29 Oct 2006 10:30:01 EST -05:00"
,
(
twz
+
1
.
days
+
1
.
second
).
inspect
end
...
...
@@ -808,12 +826,16 @@ def test_advance_1_day_expressed_as_number_of_seconds_minutes_or_hours_across_fa
assert_equal
"Sun, 29 Oct 2006 09:30:00 EST -05:00"
,
(
twz
+
86400
.
seconds
).
inspect
assert_equal
"Sun, 29 Oct 2006 09:30:00 EST -05:00"
,
twz
.
since
(
86400
).
inspect
assert_equal
"Sun, 29 Oct 2006 09:30:00 EST -05:00"
,
twz
.
since
(
86400
.
seconds
).
inspect
assert_equal
"Sun, 29 Oct 2006 09:30:00 EST -05:00"
,
twz
.
in
(
86400
).
inspect
assert_equal
"Sun, 29 Oct 2006 09:30:00 EST -05:00"
,
twz
.
in
(
86400
.
seconds
).
inspect
assert_equal
"Sun, 29 Oct 2006 09:30:00 EST -05:00"
,
twz
.
advance
(
seconds:
86400
).
inspect
assert_equal
"Sun, 29 Oct 2006 09:30:00 EST -05:00"
,
(
twz
+
1440
.
minutes
).
inspect
assert_equal
"Sun, 29 Oct 2006 09:30:00 EST -05:00"
,
twz
.
since
(
1440
.
minutes
).
inspect
assert_equal
"Sun, 29 Oct 2006 09:30:00 EST -05:00"
,
twz
.
in
(
1440
.
minutes
).
inspect
assert_equal
"Sun, 29 Oct 2006 09:30:00 EST -05:00"
,
twz
.
advance
(
minutes:
1440
).
inspect
assert_equal
"Sun, 29 Oct 2006 09:30:00 EST -05:00"
,
(
twz
+
24
.
hours
).
inspect
assert_equal
"Sun, 29 Oct 2006 09:30:00 EST -05:00"
,
twz
.
since
(
24
.
hours
).
inspect
assert_equal
"Sun, 29 Oct 2006 09:30:00 EST -05:00"
,
twz
.
in
(
24
.
hours
).
inspect
assert_equal
"Sun, 29 Oct 2006 09:30:00 EST -05:00"
,
twz
.
advance
(
hours:
24
).
inspect
end
...
...
@@ -839,6 +861,7 @@ def test_advance_1_week_across_spring_dst_transition
assert_equal
"Sat, 08 Apr 2006 10:30:00 EDT -04:00"
,
twz
.
advance
(
weeks:
1
).
inspect
assert_equal
"Sat, 08 Apr 2006 10:30:00 EDT -04:00"
,
twz
.
weeks_since
(
1
).
inspect
assert_equal
"Sat, 08 Apr 2006 10:30:00 EDT -04:00"
,
twz
.
since
(
1
.
week
).
inspect
assert_equal
"Sat, 08 Apr 2006 10:30:00 EDT -04:00"
,
twz
.
in
(
1
.
week
).
inspect
assert_equal
"Sat, 08 Apr 2006 10:30:00 EDT -04:00"
,
(
twz
+
1
.
week
).
inspect
end
...
...
@@ -855,6 +878,7 @@ def test_advance_1_week_across_fall_dst_transition
assert_equal
"Sat, 04 Nov 2006 10:30:00 EST -05:00"
,
twz
.
advance
(
weeks:
1
).
inspect
assert_equal
"Sat, 04 Nov 2006 10:30:00 EST -05:00"
,
twz
.
weeks_since
(
1
).
inspect
assert_equal
"Sat, 04 Nov 2006 10:30:00 EST -05:00"
,
twz
.
since
(
1
.
week
).
inspect
assert_equal
"Sat, 04 Nov 2006 10:30:00 EST -05:00"
,
twz
.
in
(
1
.
week
).
inspect
assert_equal
"Sat, 04 Nov 2006 10:30:00 EST -05:00"
,
(
twz
+
1
.
week
).
inspect
end
...
...
@@ -871,6 +895,7 @@ def test_advance_1_month_across_spring_dst_transition
assert_equal
"Mon, 01 May 2006 10:30:00 EDT -04:00"
,
twz
.
advance
(
months:
1
).
inspect
assert_equal
"Mon, 01 May 2006 10:30:00 EDT -04:00"
,
twz
.
months_since
(
1
).
inspect
assert_equal
"Mon, 01 May 2006 10:30:00 EDT -04:00"
,
twz
.
since
(
1
.
month
).
inspect
assert_equal
"Mon, 01 May 2006 10:30:00 EDT -04:00"
,
twz
.
in
(
1
.
month
).
inspect
assert_equal
"Mon, 01 May 2006 10:30:00 EDT -04:00"
,
(
twz
+
1
.
month
).
inspect
end
...
...
@@ -887,6 +912,7 @@ def test_advance_1_month_across_fall_dst_transition
assert_equal
"Tue, 28 Nov 2006 10:30:00 EST -05:00"
,
twz
.
advance
(
months:
1
).
inspect
assert_equal
"Tue, 28 Nov 2006 10:30:00 EST -05:00"
,
twz
.
months_since
(
1
).
inspect
assert_equal
"Tue, 28 Nov 2006 10:30:00 EST -05:00"
,
twz
.
since
(
1
.
month
).
inspect
assert_equal
"Tue, 28 Nov 2006 10:30:00 EST -05:00"
,
twz
.
in
(
1
.
month
).
inspect
assert_equal
"Tue, 28 Nov 2006 10:30:00 EST -05:00"
,
(
twz
+
1
.
month
).
inspect
end
...
...
@@ -902,6 +928,8 @@ def test_advance_1_year
twz
=
ActiveSupport
::
TimeWithZone
.
new
(
nil
,
@time_zone
,
Time
.
utc
(
2008
,
2
,
15
,
10
,
30
))
assert_equal
"Sun, 15 Feb 2009 10:30:00 EST -05:00"
,
twz
.
advance
(
years:
1
).
inspect
assert_equal
"Sun, 15 Feb 2009 10:30:00 EST -05:00"
,
twz
.
years_since
(
1
).
inspect
assert_equal
"Sun, 15 Feb 2009 10:30:00 EST -05:00"
,
twz
.
since
(
1
.
year
).
inspect
assert_equal
"Sun, 15 Feb 2009 10:30:00 EST -05:00"
,
twz
.
in
(
1
.
year
).
inspect
assert_equal
"Sun, 15 Feb 2009 10:30:00 EST -05:00"
,
(
twz
+
1
.
year
).
inspect
assert_equal
"Thu, 15 Feb 2007 10:30:00 EST -05:00"
,
twz
.
advance
(
years:
-
1
).
inspect
assert_equal
"Thu, 15 Feb 2007 10:30:00 EST -05:00"
,
twz
.
years_ago
(
1
).
inspect
...
...
@@ -912,6 +940,8 @@ def test_advance_1_year_during_dst
twz
=
ActiveSupport
::
TimeWithZone
.
new
(
nil
,
@time_zone
,
Time
.
utc
(
2008
,
7
,
15
,
10
,
30
))
assert_equal
"Wed, 15 Jul 2009 10:30:00 EDT -04:00"
,
twz
.
advance
(
years:
1
).
inspect
assert_equal
"Wed, 15 Jul 2009 10:30:00 EDT -04:00"
,
twz
.
years_since
(
1
).
inspect
assert_equal
"Wed, 15 Jul 2009 10:30:00 EDT -04:00"
,
twz
.
since
(
1
.
year
).
inspect
assert_equal
"Wed, 15 Jul 2009 10:30:00 EDT -04:00"
,
twz
.
in
(
1
.
year
).
inspect
assert_equal
"Wed, 15 Jul 2009 10:30:00 EDT -04:00"
,
(
twz
+
1
.
year
).
inspect
assert_equal
"Sun, 15 Jul 2007 10:30:00 EDT -04:00"
,
twz
.
advance
(
years:
-
1
).
inspect
assert_equal
"Sun, 15 Jul 2007 10:30:00 EDT -04:00"
,
twz
.
years_ago
(
1
).
inspect
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录