Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
0f60146c
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,体验更适合开发者的 AI 搜索 >>
未验证
提交
0f60146c
编写于
5月 06, 2020
作者:
R
Rafael França
提交者:
GitHub
5月 06, 2020
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #39169 from jonathanhefner/add-date_formats-inspect
Add DATE_FORMATS[:inspect]
上级
d22216f2
2b38bf68
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
10 addition
and
14 deletion
+10
-14
activerecord/lib/active_record/attribute_methods.rb
activerecord/lib/active_record/attribute_methods.rb
+2
-8
activerecord/test/cases/attribute_methods_test.rb
activerecord/test/cases/attribute_methods_test.rb
+1
-1
activerecord/test/cases/core_test.rb
activerecord/test/cases/core_test.rb
+5
-5
activesupport/lib/active_support/core_ext/date/conversions.rb
...vesupport/lib/active_support/core_ext/date/conversions.rb
+1
-0
activesupport/lib/active_support/core_ext/time/conversions.rb
...vesupport/lib/active_support/core_ext/time/conversions.rb
+1
-0
未找到文件。
activerecord/lib/active_record/attribute_methods.rb
浏览文件 @
0f60146c
...
@@ -401,14 +401,8 @@ def attributes_for_create(attribute_names)
...
@@ -401,14 +401,8 @@ def attributes_for_create(attribute_names)
def
format_for_inspect
(
value
)
def
format_for_inspect
(
value
)
if
value
.
is_a?
(
String
)
&&
value
.
length
>
50
if
value
.
is_a?
(
String
)
&&
value
.
length
>
50
"
#{
value
[
0
,
50
]
}
..."
.
inspect
"
#{
value
[
0
,
50
]
}
..."
.
inspect
elsif
value
.
is_a?
(
Time
)
elsif
value
.
is_a?
(
Date
)
||
value
.
is_a?
(
Time
)
if
Time
::
DATE_FORMATS
[
:db
].
respond_to?
(
:call
)
%("#{value.to_s(:inspect)}")
Time
::
DATE_FORMATS
[
:db
].
call
(
value
)
else
%("#{value.strftime(Time::DATE_FORMATS[:db] + '.%9N')}")
end
elsif
value
.
is_a?
(
Date
)
%("#{value.to_s(:db)}")
else
else
value
.
inspect
value
.
inspect
end
end
...
...
activerecord/test/cases/attribute_methods_test.rb
浏览文件 @
0f60146c
...
@@ -39,7 +39,7 @@ def setup
...
@@ -39,7 +39,7 @@ def setup
test
"attribute_for_inspect with a date"
do
test
"attribute_for_inspect with a date"
do
t
=
topics
(
:first
)
t
=
topics
(
:first
)
assert_equal
%("#{t.written_on.to_s(:
db)}.#{t.written_on.strftime('%9N'
)}")
,
t
.
attribute_for_inspect
(
:written_on
)
assert_equal
%("#{t.written_on.to_s(:
inspect
)}")
,
t
.
attribute_for_inspect
(
:written_on
)
end
end
test
"attribute_for_inspect with an array"
do
test
"attribute_for_inspect with an array"
do
...
...
activerecord/test/cases/core_test.rb
浏览文件 @
0f60146c
...
@@ -18,18 +18,18 @@ def test_inspect_class
...
@@ -18,18 +18,18 @@ def test_inspect_class
def
test_inspect_instance
def
test_inspect_instance
topic
=
topics
(
:first
)
topic
=
topics
(
:first
)
assert_equal
%(#<Topic id: 1, title: "The First Topic", author_name: "David", author_email_address: "david@loudthinking.com", written_on: "#{topic.written_on.to_s(:
db)}.#{topic.written_on.strftime('%9N')}", bonus_time: "#{topic.bonus_time.to_s(:db)}.#{topic.bonus_time.strftime('%9N')}", last_read: "#{topic.last_read.to_s(:db)}", content: "Have a nice day", important: nil, approved: false, replies_count: 1, unique_replies_count: 0, parent_id: nil, parent_title: nil, type: nil, group: nil, created_at: "#{topic.created_at.to_s(:db)}.#{topic.created_at.strftime('%9N')}", updated_at: "#{topic.updated_at.to_s(:db)}.#{topic.updated_at.strftime('%9N'
)}">)
,
topic
.
inspect
assert_equal
%(#<Topic id: 1, title: "The First Topic", author_name: "David", author_email_address: "david@loudthinking.com", written_on: "#{topic.written_on.to_s(:
inspect)}", bonus_time: "#{topic.bonus_time.to_s(:inspect)}", last_read: "#{topic.last_read.to_s(:inspect)}", content: "Have a nice day", important: nil, approved: false, replies_count: 1, unique_replies_count: 0, parent_id: nil, parent_title: nil, type: nil, group: nil, created_at: "#{topic.created_at.to_s(:inspect)}", updated_at: "#{topic.updated_at.to_s(:inspect
)}">)
,
topic
.
inspect
end
end
def
test_inspect_instance_with_lambda_date_formatter
def
test_inspect_instance_with_lambda_date_formatter
before
=
Time
::
DATE_FORMATS
[
:
db
]
before
=
Time
::
DATE_FORMATS
[
:
inspect
]
Time
::
DATE_FORMATS
[
:
db
]
=
->
(
date
)
{
"my_format"
}
Time
::
DATE_FORMATS
[
:
inspect
]
=
->
(
date
)
{
"my_format"
}
topic
=
topics
(
:first
)
topic
=
topics
(
:first
)
assert_equal
%(#<Topic id: 1, title: "The First Topic", author_name: "David", author_email_address: "david@loudthinking.com", written_on:
my_format, bonus_time: my_format, last_read: "2004-04-15", content: "Have a nice day", important: nil, approved: false, replies_count: 1, unique_replies_count: 0, parent_id: nil, parent_title: nil, type: nil, group: nil, created_at: my_format, updated_at: my_format
>)
,
topic
.
inspect
assert_equal
%(#<Topic id: 1, title: "The First Topic", author_name: "David", author_email_address: "david@loudthinking.com", written_on:
"my_format", bonus_time: "my_format", last_read: "2004-04-15", content: "Have a nice day", important: nil, approved: false, replies_count: 1, unique_replies_count: 0, parent_id: nil, parent_title: nil, type: nil, group: nil, created_at: "my_format", updated_at: "my_format"
>)
,
topic
.
inspect
ensure
ensure
Time
::
DATE_FORMATS
[
:
db
]
=
before
Time
::
DATE_FORMATS
[
:
inspect
]
=
before
end
end
def
test_inspect_new_instance
def
test_inspect_new_instance
...
...
activesupport/lib/active_support/core_ext/date/conversions.rb
浏览文件 @
0f60146c
...
@@ -10,6 +10,7 @@ class Date
...
@@ -10,6 +10,7 @@ class Date
short:
"%d %b"
,
short:
"%d %b"
,
long:
"%B %d, %Y"
,
long:
"%B %d, %Y"
,
db:
"%Y-%m-%d"
,
db:
"%Y-%m-%d"
,
inspect:
"%Y-%m-%d"
,
number:
"%Y%m%d"
,
number:
"%Y%m%d"
,
long_ordinal:
lambda
{
|
date
|
long_ordinal:
lambda
{
|
date
|
day_format
=
ActiveSupport
::
Inflector
.
ordinalize
(
date
.
day
)
day_format
=
ActiveSupport
::
Inflector
.
ordinalize
(
date
.
day
)
...
...
activesupport/lib/active_support/core_ext/time/conversions.rb
浏览文件 @
0f60146c
...
@@ -6,6 +6,7 @@
...
@@ -6,6 +6,7 @@
class
Time
class
Time
DATE_FORMATS
=
{
DATE_FORMATS
=
{
db:
"%Y-%m-%d %H:%M:%S"
,
db:
"%Y-%m-%d %H:%M:%S"
,
inspect:
"%Y-%m-%d %H:%M:%S.%9N %z"
,
number:
"%Y%m%d%H%M%S"
,
number:
"%Y%m%d%H%M%S"
,
nsec:
"%Y%m%d%H%M%S%9N"
,
nsec:
"%Y%m%d%H%M%S%9N"
,
usec:
"%Y%m%d%H%M%S%6N"
,
usec:
"%Y%m%d%H%M%S%6N"
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录