Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
3ef20aa6
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,发现更多精彩内容 >>
提交
3ef20aa6
编写于
12月 20, 2011
作者:
A
Aaron Patterson
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #4035 from lest/date-type-cast
handle not only strings in date type cast
上级
7ba28d43
e2d19d60
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
19 addition
and
7 deletion
+19
-7
activerecord/lib/active_record/connection_adapters/column.rb
activerecord/lib/active_record/connection_adapters/column.rb
+11
-7
activerecord/test/cases/attribute_methods_test.rb
activerecord/test/cases/attribute_methods_test.rb
+8
-0
未找到文件。
activerecord/lib/active_record/connection_adapters/column.rb
浏览文件 @
3ef20aa6
...
...
@@ -80,7 +80,7 @@ def type_cast(value)
when
:decimal
then
klass
.
value_to_decimal
(
value
)
when
:datetime
,
:timestamp
then
klass
.
string_to_time
(
value
)
when
:time
then
klass
.
string_to_dummy_time
(
value
)
when
:date
then
klass
.
string
_to_date
(
value
)
when
:date
then
klass
.
value
_to_date
(
value
)
when
:binary
then
klass
.
binary_to_string
(
value
)
when
:boolean
then
klass
.
value_to_boolean
(
value
)
else
value
...
...
@@ -97,7 +97,7 @@ def type_cast_code(var_name)
when
:decimal
then
"
#{
klass
}
.value_to_decimal(
#{
var_name
}
)"
when
:datetime
,
:timestamp
then
"
#{
klass
}
.string_to_time(
#{
var_name
}
)"
when
:time
then
"
#{
klass
}
.string_to_dummy_time(
#{
var_name
}
)"
when
:date
then
"
#{
klass
}
.
string
_to_date(
#{
var_name
}
)"
when
:date
then
"
#{
klass
}
.
value
_to_date(
#{
var_name
}
)"
when
:binary
then
"
#{
klass
}
.binary_to_string(
#{
var_name
}
)"
when
:boolean
then
"
#{
klass
}
.value_to_boolean(
#{
var_name
}
)"
else
var_name
...
...
@@ -132,11 +132,15 @@ def binary_to_string(value)
value
end
def
string_to_date
(
string
)
return
string
unless
string
.
is_a?
(
String
)
return
nil
if
string
.
empty?
fast_string_to_date
(
string
)
||
fallback_string_to_date
(
string
)
def
value_to_date
(
value
)
if
value
.
is_a?
(
String
)
return
nil
if
value
.
empty?
fast_string_to_date
(
value
)
||
fallback_string_to_date
(
value
)
elsif
value
.
respond_to?
(
:to_date
)
value
.
to_date
else
value
end
end
def
string_to_time
(
string
)
...
...
activerecord/test/cases/attribute_methods_test.rb
浏览文件 @
3ef20aa6
...
...
@@ -518,6 +518,14 @@ def test_write_nil_to_time_attributes
end
end
def
test_write_time_to_date_attributes
in_time_zone
"Pacific Time (US & Canada)"
do
record
=
@target
.
new
record
.
last_read
=
Time
.
utc
(
2010
,
1
,
1
,
10
)
assert_equal
Date
.
civil
(
2010
,
1
,
1
),
record
.
last_read
end
end
def
test_time_attributes_are_retrieved_in_current_time_zone
in_time_zone
"Pacific Time (US & Canada)"
do
utc_time
=
Time
.
utc
(
2008
,
1
,
1
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录