Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
ebc6b171
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,发现更多精彩内容 >>
未验证
提交
ebc6b171
编写于
11月 15, 2017
作者:
A
Andrew White
提交者:
GitHub
11月 15, 2017
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #31128 from rails/handle-ambigious-times
Handle `TZInfo::AmbiguousTime` errors
上级
706b4bee
2eea6458
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
66 addition
and
1 deletion
+66
-1
activesupport/CHANGELOG.md
activesupport/CHANGELOG.md
+27
-0
activesupport/lib/active_support/values/time_zone.rb
activesupport/lib/active_support/values/time_zone.rb
+1
-1
activesupport/test/core_ext/time_with_zone_test.rb
activesupport/test/core_ext/time_with_zone_test.rb
+12
-0
activesupport/test/time_zone_test.rb
activesupport/test/time_zone_test.rb
+26
-0
未找到文件。
activesupport/CHANGELOG.md
浏览文件 @
ebc6b171
*
Handle
`TZInfo::AmbiguousTime`
errors
Make `ActiveSupport::TimeWithZone` match Ruby's handling of ambiguous
times by choosing the later period, e.g.
Ruby:
```
ENV["TZ"] = "Europe/Moscow"
Time.local(2014, 10, 26, 1, 0, 0) # => 2014-10-26 01:00:00 +0300
```
Before:
```
>> "2014-10-26 01:00:00".in_time_zone("Moscow")
TZInfo::AmbiguousTime: 26/10/2014 01:00 is an ambiguous local time.
```
After:
```
>> "2014-10-26 01:00:00".in_time_zone("Moscow")
=> Sun, 26 Oct 2014 01:00:00 MSK +03:00
```
Fixes #17395.
*Andrew White*
*
Redis cache store.
*
Redis cache store.
```
```
...
...
activesupport/lib/active_support/values/time_zone.rb
浏览文件 @
ebc6b171
...
@@ -506,7 +506,7 @@ def period_for_utc(time)
...
@@ -506,7 +506,7 @@ def period_for_utc(time)
# Available so that TimeZone instances respond like TZInfo::Timezone
# Available so that TimeZone instances respond like TZInfo::Timezone
# instances.
# instances.
def
period_for_local
(
time
,
dst
=
true
)
def
period_for_local
(
time
,
dst
=
true
)
tzinfo
.
period_for_local
(
time
,
dst
)
tzinfo
.
period_for_local
(
time
,
dst
)
{
|
periods
|
periods
.
last
}
end
end
def
periods_for_local
(
time
)
#:nodoc:
def
periods_for_local
(
time
)
#:nodoc:
...
...
activesupport/test/core_ext/time_with_zone_test.rb
浏览文件 @
ebc6b171
...
@@ -50,6 +50,12 @@ def test_in_time_zone_with_bad_argument
...
@@ -50,6 +50,12 @@ def test_in_time_zone_with_bad_argument
assert_raise
(
ArgumentError
)
{
@twz
.
in_time_zone
(
Object
.
new
)
}
assert_raise
(
ArgumentError
)
{
@twz
.
in_time_zone
(
Object
.
new
)
}
end
end
def
test_in_time_zone_with_ambiguous_time
with_env_tz
"Europe/Moscow"
do
assert_equal
Time
.
utc
(
2014
,
10
,
25
,
22
,
0
,
0
),
Time
.
local
(
2014
,
10
,
26
,
1
,
0
,
0
).
in_time_zone
(
"Moscow"
)
end
end
def
test_localtime
def
test_localtime
assert_equal
@twz
.
localtime
,
@twz
.
utc
.
getlocal
assert_equal
@twz
.
localtime
,
@twz
.
utc
.
getlocal
assert_instance_of
Time
,
@twz
.
localtime
assert_instance_of
Time
,
@twz
.
localtime
...
@@ -1301,4 +1307,10 @@ def test_in_time_zone_with_invalid_argument
...
@@ -1301,4 +1307,10 @@ def test_in_time_zone_with_invalid_argument
assert_raise
(
ArgumentError
)
{
@u
.
in_time_zone
(
Object
.
new
)
}
assert_raise
(
ArgumentError
)
{
@u
.
in_time_zone
(
Object
.
new
)
}
assert_raise
(
ArgumentError
)
{
@z
.
in_time_zone
(
Object
.
new
)
}
assert_raise
(
ArgumentError
)
{
@z
.
in_time_zone
(
Object
.
new
)
}
end
end
def
test_in_time_zone_with_ambiguous_time
with_tz_default
"Moscow"
do
assert_equal
Time
.
utc
(
2014
,
10
,
25
,
22
,
0
,
0
),
"2014-10-26 01:00:00"
.
in_time_zone
end
end
end
end
activesupport/test/time_zone_test.rb
浏览文件 @
ebc6b171
...
@@ -32,6 +32,12 @@ def test_period_for_local
...
@@ -32,6 +32,12 @@ def test_period_for_local
end
end
end
end
def
test_period_for_local_with_ambigiuous_time
zone
=
ActiveSupport
::
TimeZone
[
"Moscow"
]
period
=
zone
.
period_for_local
(
Time
.
utc
(
2015
,
1
,
1
))
assert_equal
period
,
zone
.
period_for_local
(
Time
.
utc
(
2014
,
10
,
26
,
1
,
0
,
0
))
end
def
test_from_integer_to_map
def
test_from_integer_to_map
assert_instance_of
ActiveSupport
::
TimeZone
,
ActiveSupport
::
TimeZone
[
-
28800
]
# PST
assert_instance_of
ActiveSupport
::
TimeZone
,
ActiveSupport
::
TimeZone
[
-
28800
]
# PST
end
end
...
@@ -195,6 +201,11 @@ def test_local_enforces_fall_dst_rules
...
@@ -195,6 +201,11 @@ def test_local_enforces_fall_dst_rules
assert_equal
"EDT"
,
twz
.
zone
assert_equal
"EDT"
,
twz
.
zone
end
end
def
test_local_with_ambiguous_time
zone
=
ActiveSupport
::
TimeZone
[
"Moscow"
]
assert_equal
Time
.
utc
(
2014
,
10
,
25
,
22
,
0
,
0
),
zone
.
local
(
2014
,
10
,
26
,
1
,
0
,
0
)
end
def
test_at
def
test_at
zone
=
ActiveSupport
::
TimeZone
[
"Eastern Time (US & Canada)"
]
zone
=
ActiveSupport
::
TimeZone
[
"Eastern Time (US & Canada)"
]
secs
=
946684800.0
secs
=
946684800.0
...
@@ -303,6 +314,11 @@ def test_iso8601_handles_dst_jump
...
@@ -303,6 +314,11 @@ def test_iso8601_handles_dst_jump
end
end
end
end
def
test_iso8601_with_ambiguous_time
zone
=
ActiveSupport
::
TimeZone
[
"Moscow"
]
assert_equal
Time
.
utc
(
2014
,
10
,
25
,
22
,
0
,
0
),
zone
.
parse
(
"2014-10-26T01:00:00"
)
end
def
test_parse
def
test_parse
zone
=
ActiveSupport
::
TimeZone
[
"Eastern Time (US & Canada)"
]
zone
=
ActiveSupport
::
TimeZone
[
"Eastern Time (US & Canada)"
]
twz
=
zone
.
parse
(
"1999-12-31 19:00:00"
)
twz
=
zone
.
parse
(
"1999-12-31 19:00:00"
)
...
@@ -412,6 +428,11 @@ def test_parse_with_invalid_date
...
@@ -412,6 +428,11 @@ def test_parse_with_invalid_date
assert_equal
"argument out of range"
,
exception
.
message
assert_equal
"argument out of range"
,
exception
.
message
end
end
def
test_parse_with_ambiguous_time
zone
=
ActiveSupport
::
TimeZone
[
"Moscow"
]
assert_equal
Time
.
utc
(
2014
,
10
,
25
,
22
,
0
,
0
),
zone
.
parse
(
"2014-10-26 01:00:00"
)
end
def
test_rfc3339
def
test_rfc3339
zone
=
ActiveSupport
::
TimeZone
[
"Eastern Time (US & Canada)"
]
zone
=
ActiveSupport
::
TimeZone
[
"Eastern Time (US & Canada)"
]
twz
=
zone
.
rfc3339
(
"1999-12-31T14:00:00-10:00"
)
twz
=
zone
.
rfc3339
(
"1999-12-31T14:00:00-10:00"
)
...
@@ -604,6 +625,11 @@ def test_strptime_with_timestamp_milliseconds
...
@@ -604,6 +625,11 @@ def test_strptime_with_timestamp_milliseconds
end
end
end
end
def
test_strptime_with_ambiguous_time
zone
=
ActiveSupport
::
TimeZone
[
"Moscow"
]
assert_equal
Time
.
utc
(
2014
,
10
,
25
,
22
,
0
,
0
),
zone
.
strptime
(
"2014-10-26 01:00:00"
,
"%Y-%m-%d %H:%M:%S"
)
end
def
test_utc_offset_lazy_loaded_from_tzinfo_when_not_passed_in_to_initialize
def
test_utc_offset_lazy_loaded_from_tzinfo_when_not_passed_in_to_initialize
tzinfo
=
TZInfo
::
Timezone
.
get
(
"America/New_York"
)
tzinfo
=
TZInfo
::
Timezone
.
get
(
"America/New_York"
)
zone
=
ActiveSupport
::
TimeZone
.
create
(
tzinfo
.
name
,
nil
,
tzinfo
)
zone
=
ActiveSupport
::
TimeZone
.
create
(
tzinfo
.
name
,
nil
,
tzinfo
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录