Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
9a9ef963
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,发现更多精彩内容 >>
未验证
提交
9a9ef963
编写于
3月 26, 2018
作者:
R
Rafael França
提交者:
GitHub
3月 26, 2018
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #32185 from nholden/human_readable_date_time_comparisons
Add `before?` and `after?` methods to date and time classes
上级
93e6b5c2
20fa0d92
变更
9
显示空白变更内容
内联
并排
Showing
9 changed file
with
63 addition
and
0 deletion
+63
-0
activesupport/CHANGELOG.md
activesupport/CHANGELOG.md
+5
-0
activesupport/lib/active_support/core_ext/date/calculations.rb
...esupport/lib/active_support/core_ext/date/calculations.rb
+2
-0
activesupport/lib/active_support/core_ext/date_time/calculations.rb
...ort/lib/active_support/core_ext/date_time/calculations.rb
+2
-0
activesupport/lib/active_support/core_ext/time/calculations.rb
...esupport/lib/active_support/core_ext/time/calculations.rb
+2
-0
activesupport/lib/active_support/time_with_zone.rb
activesupport/lib/active_support/time_with_zone.rb
+2
-0
activesupport/test/core_ext/date_ext_test.rb
activesupport/test/core_ext/date_ext_test.rb
+12
-0
activesupport/test/core_ext/date_time_ext_test.rb
activesupport/test/core_ext/date_time_ext_test.rb
+12
-0
activesupport/test/core_ext/time_ext_test.rb
activesupport/test/core_ext/time_ext_test.rb
+12
-0
activesupport/test/core_ext/time_with_zone_test.rb
activesupport/test/core_ext/time_with_zone_test.rb
+14
-0
未找到文件。
activesupport/CHANGELOG.md
浏览文件 @
9a9ef963
...
@@ -6,6 +6,11 @@
...
@@ -6,6 +6,11 @@
*Ashe Connor*, *Aaron Patterson*
*Ashe Connor*, *Aaron Patterson*
*
Add
`before?`
and
`after?`
methods to
`Date`
,
`DateTime`
,
`Time`
, and
`TimeWithZone`
.
*Nick Holden*
*
Add
`:private`
option to ActiveSupport's
`Module#delegate`
*
Add
`:private`
option to ActiveSupport's
`Module#delegate`
in order to delegate methods as private:
in order to delegate methods as private:
...
...
activesupport/lib/active_support/core_ext/date/calculations.rb
浏览文件 @
9a9ef963
...
@@ -142,4 +142,6 @@ def compare_with_coercion(other)
...
@@ -142,4 +142,6 @@ def compare_with_coercion(other)
end
end
alias_method
:compare_without_coercion
,
:<=>
alias_method
:compare_without_coercion
,
:<=>
alias_method
:<=>
,
:compare_with_coercion
alias_method
:<=>
,
:compare_with_coercion
alias_method
:before?
,
:<
alias_method
:after?
,
:
>
end
end
activesupport/lib/active_support/core_ext/date_time/calculations.rb
浏览文件 @
9a9ef963
...
@@ -208,4 +208,6 @@ def <=>(other)
...
@@ -208,4 +208,6 @@ def <=>(other)
super
super
end
end
end
end
alias_method
:before?
,
:<
alias_method
:after?
,
:
>
end
end
activesupport/lib/active_support/core_ext/time/calculations.rb
浏览文件 @
9a9ef963
...
@@ -302,6 +302,8 @@ def compare_with_coercion(other)
...
@@ -302,6 +302,8 @@ def compare_with_coercion(other)
end
end
alias_method
:compare_without_coercion
,
:<=>
alias_method
:compare_without_coercion
,
:<=>
alias_method
:<=>
,
:compare_with_coercion
alias_method
:<=>
,
:compare_with_coercion
alias_method
:before?
,
:<
alias_method
:after?
,
:
>
# Layers additional behavior on Time#eql? so that ActiveSupport::TimeWithZone instances
# Layers additional behavior on Time#eql? so that ActiveSupport::TimeWithZone instances
# can be eql? to an equivalent Time
# can be eql? to an equivalent Time
...
...
activesupport/lib/active_support/time_with_zone.rb
浏览文件 @
9a9ef963
...
@@ -225,6 +225,8 @@ def strftime(format)
...
@@ -225,6 +225,8 @@ def strftime(format)
def
<
=>
(
other
)
def
<
=>
(
other
)
utc
<=>
other
utc
<=>
other
end
end
alias_method
:before?
,
:<
alias_method
:after?
,
:
>
# Returns true if the current object's time is within the specified
# Returns true if the current object's time is within the specified
# +min+ and +max+ time.
# +min+ and +max+ time.
...
...
activesupport/test/core_ext/date_ext_test.rb
浏览文件 @
9a9ef963
...
@@ -360,6 +360,18 @@ def test_future
...
@@ -360,6 +360,18 @@ def test_future
end
end
end
end
def
test_before
assert_equal
false
,
Date
.
new
(
2017
,
3
,
6
).
before?
(
Date
.
new
(
2017
,
3
,
5
))
assert_equal
false
,
Date
.
new
(
2017
,
3
,
6
).
before?
(
Date
.
new
(
2017
,
3
,
6
))
assert_equal
true
,
Date
.
new
(
2017
,
3
,
6
).
before?
(
Date
.
new
(
2017
,
3
,
7
))
end
def
test_after
assert_equal
true
,
Date
.
new
(
2017
,
3
,
6
).
after?
(
Date
.
new
(
2017
,
3
,
5
))
assert_equal
false
,
Date
.
new
(
2017
,
3
,
6
).
after?
(
Date
.
new
(
2017
,
3
,
6
))
assert_equal
false
,
Date
.
new
(
2017
,
3
,
6
).
after?
(
Date
.
new
(
2017
,
3
,
7
))
end
def
test_current_returns_date_today_when_zone_not_set
def
test_current_returns_date_today_when_zone_not_set
with_env_tz
"US/Central"
do
with_env_tz
"US/Central"
do
Time
.
stub
(
:now
,
Time
.
local
(
1999
,
12
,
31
,
23
))
do
Time
.
stub
(
:now
,
Time
.
local
(
1999
,
12
,
31
,
23
))
do
...
...
activesupport/test/core_ext/date_time_ext_test.rb
浏览文件 @
9a9ef963
...
@@ -285,6 +285,18 @@ def test_future_without_offset
...
@@ -285,6 +285,18 @@ def test_future_without_offset
end
end
end
end
def
test_before
assert_equal
false
,
DateTime
.
civil
(
2017
,
3
,
6
,
12
,
0
,
0
).
before?
(
DateTime
.
civil
(
2017
,
3
,
6
,
11
,
59
,
59
))
assert_equal
false
,
DateTime
.
civil
(
2017
,
3
,
6
,
12
,
0
,
0
).
before?
(
DateTime
.
civil
(
2017
,
3
,
6
,
12
,
0
,
0
))
assert_equal
true
,
DateTime
.
civil
(
2017
,
3
,
6
,
12
,
0
,
0
).
before?
(
DateTime
.
civil
(
2017
,
3
,
6
,
12
,
00
,
1
))
end
def
test_after
assert_equal
true
,
DateTime
.
civil
(
2017
,
3
,
6
,
12
,
0
,
0
).
after?
(
DateTime
.
civil
(
2017
,
3
,
6
,
11
,
59
,
59
))
assert_equal
false
,
DateTime
.
civil
(
2017
,
3
,
6
,
12
,
0
,
0
).
after?
(
DateTime
.
civil
(
2017
,
3
,
6
,
12
,
0
,
0
))
assert_equal
false
,
DateTime
.
civil
(
2017
,
3
,
6
,
12
,
0
,
0
).
after?
(
DateTime
.
civil
(
2017
,
3
,
6
,
12
,
00
,
1
))
end
def
test_current_returns_date_today_when_zone_is_not_set
def
test_current_returns_date_today_when_zone_is_not_set
with_env_tz
"US/Eastern"
do
with_env_tz
"US/Eastern"
do
Time
.
stub
(
:now
,
Time
.
local
(
1999
,
12
,
31
,
23
,
59
,
59
))
do
Time
.
stub
(
:now
,
Time
.
local
(
1999
,
12
,
31
,
23
,
59
,
59
))
do
...
...
activesupport/test/core_ext/time_ext_test.rb
浏览文件 @
9a9ef963
...
@@ -736,6 +736,18 @@ def test_future_with_time_current_as_time_with_zone
...
@@ -736,6 +736,18 @@ def test_future_with_time_current_as_time_with_zone
end
end
end
end
def
test_before
assert_equal
false
,
Time
.
utc
(
2017
,
3
,
6
,
12
,
0
,
0
).
before?
(
Time
.
utc
(
2017
,
3
,
6
,
11
,
59
,
59
))
assert_equal
false
,
Time
.
utc
(
2017
,
3
,
6
,
12
,
0
,
0
).
before?
(
Time
.
utc
(
2017
,
3
,
6
,
12
,
0
,
0
))
assert_equal
true
,
Time
.
utc
(
2017
,
3
,
6
,
12
,
0
,
0
).
before?
(
Time
.
utc
(
2017
,
3
,
6
,
12
,
00
,
1
))
end
def
test_after
assert_equal
true
,
Time
.
utc
(
2017
,
3
,
6
,
12
,
0
,
0
).
after?
(
Time
.
utc
(
2017
,
3
,
6
,
11
,
59
,
59
))
assert_equal
false
,
Time
.
utc
(
2017
,
3
,
6
,
12
,
0
,
0
).
after?
(
Time
.
utc
(
2017
,
3
,
6
,
12
,
0
,
0
))
assert_equal
false
,
Time
.
utc
(
2017
,
3
,
6
,
12
,
0
,
0
).
after?
(
Time
.
utc
(
2017
,
3
,
6
,
12
,
00
,
1
))
end
def
test_acts_like_time
def
test_acts_like_time
assert_predicate
Time
.
new
,
:acts_like_time?
assert_predicate
Time
.
new
,
:acts_like_time?
end
end
...
...
activesupport/test/core_ext/time_with_zone_test.rb
浏览文件 @
9a9ef963
...
@@ -289,6 +289,20 @@ def test_future_with_time_current_as_time_with_zone
...
@@ -289,6 +289,20 @@ def test_future_with_time_current_as_time_with_zone
end
end
end
end
def
test_before
twz
=
ActiveSupport
::
TimeWithZone
.
new
(
Time
.
utc
(
2017
,
3
,
6
,
12
,
0
,
0
),
@time_zone
)
assert_equal
false
,
twz
.
before?
(
ActiveSupport
::
TimeWithZone
.
new
(
Time
.
utc
(
2017
,
3
,
6
,
11
,
59
,
59
),
@time_zone
))
assert_equal
false
,
twz
.
before?
(
ActiveSupport
::
TimeWithZone
.
new
(
Time
.
utc
(
2017
,
3
,
6
,
12
,
0
,
0
),
@time_zone
))
assert_equal
true
,
twz
.
before?
(
ActiveSupport
::
TimeWithZone
.
new
(
Time
.
utc
(
2017
,
3
,
6
,
12
,
00
,
1
),
@time_zone
))
end
def
test_after
twz
=
ActiveSupport
::
TimeWithZone
.
new
(
Time
.
utc
(
2017
,
3
,
6
,
12
,
0
,
0
),
@time_zone
)
assert_equal
true
,
twz
.
after?
(
ActiveSupport
::
TimeWithZone
.
new
(
Time
.
utc
(
2017
,
3
,
6
,
11
,
59
,
59
),
@time_zone
))
assert_equal
false
,
twz
.
after?
(
ActiveSupport
::
TimeWithZone
.
new
(
Time
.
utc
(
2017
,
3
,
6
,
12
,
0
,
0
),
@time_zone
))
assert_equal
false
,
twz
.
after?
(
ActiveSupport
::
TimeWithZone
.
new
(
Time
.
utc
(
2017
,
3
,
6
,
12
,
00
,
1
),
@time_zone
))
end
def
test_eql?
def
test_eql?
assert_equal
true
,
@twz
.
eql?
(
@twz
.
dup
)
assert_equal
true
,
@twz
.
eql?
(
@twz
.
dup
)
assert_equal
true
,
@twz
.
eql?
(
Time
.
utc
(
2000
))
assert_equal
true
,
@twz
.
eql?
(
Time
.
utc
(
2000
))
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录