Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
00de820f
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,发现更多精彩内容 >>
提交
00de820f
编写于
10月 28, 2014
作者:
A
Andrew White
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #17310 from pabloh/optimize_strftime
Optimize TimeWithZoneTest#strftime
上级
df0ea90c
1897d3a5
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
16 addition
and
10 deletion
+16
-10
activesupport/CHANGELOG.md
activesupport/CHANGELOG.md
+5
-0
activesupport/lib/active_support/time_with_zone.rb
activesupport/lib/active_support/time_with_zone.rb
+6
-10
activesupport/test/core_ext/time_with_zone_test.rb
activesupport/test/core_ext/time_with_zone_test.rb
+5
-0
未找到文件。
activesupport/CHANGELOG.md
浏览文件 @
00de820f
*
TimeWithZone#strftime now delegates every directive to Time#strftime except for '%Z',
it also now correctly handles escaped '%' characters placed just before time zone related directives.
*Pablo Herrero*
*
Corrected Inflector#underscore handling of multiple successive acroynms.
*James Le Cuirot*
...
...
activesupport/lib/active_support/time_with_zone.rb
浏览文件 @
00de820f
...
...
@@ -75,8 +75,8 @@ def in_time_zone(new_zone = ::Time.zone)
# Returns a <tt>Time.local()</tt> instance of the simultaneous time in your
# system's <tt>ENV['TZ']</tt> zone.
def
localtime
utc
.
respond_to?
(
:getlocal
)
?
utc
.
getlocal
:
utc
.
to_time
.
getlocal
def
localtime
(
utc_offset
=
nil
)
utc
.
respond_to?
(
:getlocal
)
?
utc
.
getlocal
(
utc_offset
)
:
utc
.
to_time
.
getlocal
(
utc_offset
)
end
alias_method
:getlocal
,
:localtime
...
...
@@ -201,15 +201,11 @@ def to_s(format = :default)
end
alias_method
:to_formatted_s
,
:to_s
# Replaces <tt>%Z</tt> and <tt>%z</tt> directives with +zone+ and
# +formatted_offset+, respectively, before passing to Time#strftime, so
# that zone information is correct
# Replaces <tt>%Z</tt> directive with +zone before passing to Time#strftime,
# so that zone information is correct.
def
strftime
(
format
)
format
=
format
.
gsub
(
'%Z'
,
zone
)
.
gsub
(
'%z'
,
formatted_offset
(
false
))
.
gsub
(
'%:z'
,
formatted_offset
(
true
))
.
gsub
(
'%::z'
,
formatted_offset
(
true
)
+
":00"
)
time
.
strftime
(
format
)
format
=
format
.
gsub
(
/((?:\A|[^%])(?:%%)*)%Z/
,
"
\\
1
#{
zone
}
"
)
getlocal
(
utc_offset
).
strftime
(
format
)
end
# Use the time in UTC for comparisons.
...
...
activesupport/test/core_ext/time_with_zone_test.rb
浏览文件 @
00de820f
...
...
@@ -79,6 +79,11 @@ def test_strftime
assert_equal
'1999-12-31 19:00:00 EST -0500'
,
@twz
.
strftime
(
'%Y-%m-%d %H:%M:%S %Z %z'
)
end
def
test_strftime_with_escaping
assert_equal
'%Z %z'
,
@twz
.
strftime
(
'%%Z %%z'
)
assert_equal
'%EST %-0500'
,
@twz
.
strftime
(
'%%%Z %%%z'
)
end
def
test_inspect
assert_equal
'Fri, 31 Dec 1999 19:00:00 EST -05:00'
,
@twz
.
inspect
end
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录