Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
4ea06701
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,发现更多精彩内容 >>
提交
4ea06701
编写于
2月 18, 2019
作者:
R
Ryuta Kamizono
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #29651 from Sayanc93/return-correct-date
Return correct date in ActiveModel for time to date conversions
上级
1dfd0147
eb73dfc0
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
30 addition
and
2 deletion
+30
-2
activemodel/CHANGELOG.md
activemodel/CHANGELOG.md
+18
-1
activemodel/lib/active_model/type/date.rb
activemodel/lib/active_model/type/date.rb
+1
-1
activemodel/test/cases/type/date_test.rb
activemodel/test/cases/type/date_test.rb
+11
-0
未找到文件。
activemodel/CHANGELOG.md
浏览文件 @
4ea06701
*
Fix year value when casting a multiparameter time hash
*
Fix date value when casting a multiparameter date hash to not convert
from Gregorian date to Julian date.
Before:
Day.new({"day(1i)"=>"1", "day(2i)"=>"1", "day(3i)"=>"1"})
=> #<Day id: nil, day: "0001-01-03", created_at: nil, updated_at: nil>
After:
Day.new({"day(1i)"=>"1", "day(2i)"=>"1", "day(3i)"=>"1"})
=> #<Day id: nil, day: "0001-01-01", created_at: nil, updated_at: nil>
Fixes #28521.
*Sayan Chakraborty*
*
Fix year value when casting a multiparameter time hash.
When assigning a hash to a time attribute that's missing a year component
(e.g. a `time_select` with `:ignore_date` set to `true`) then the year
...
...
activemodel/lib/active_model/type/date.rb
浏览文件 @
4ea06701
...
...
@@ -46,7 +46,7 @@ def new_date(year, mon, mday)
def
value_from_multiparameter_assignment
(
*
)
time
=
super
time
&&
time
.
to_date
time
&&
new_date
(
time
.
year
,
time
.
mon
,
time
.
mday
)
end
end
end
...
...
activemodel/test/cases/type/date_test.rb
浏览文件 @
4ea06701
...
...
@@ -18,6 +18,17 @@ def test_type_cast_date
assert_equal
date_string
,
type
.
cast
(
date_string
).
strftime
(
"%F"
)
assert_equal
date_string
,
type
.
cast
(
values_hash
).
strftime
(
"%F"
)
end
def
test_returns_correct_year
type
=
Type
::
Date
.
new
time
=
::
Time
.
utc
(
1
,
1
,
1
)
date
=
::
Date
.
new
(
time
.
year
,
time
.
mon
,
time
.
mday
)
values_hash_for_multiparameter_assignment
=
{
1
=>
1
,
2
=>
1
,
3
=>
1
}
assert_equal
date
,
type
.
cast
(
values_hash_for_multiparameter_assignment
)
end
end
end
end
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录