Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
1b6bbb09
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,发现更多精彩内容 >>
提交
1b6bbb09
编写于
6月 07, 2013
作者:
A
Anatoli Makarevich
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Added Time#middle_of_day
Added middle_of_day method to Date and DateTime
上级
94725b81
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
51 addition
and
1 deletion
+51
-1
activesupport/lib/active_support/core_ext/date/calculations.rb
...esupport/lib/active_support/core_ext/date/calculations.rb
+11
-1
activesupport/lib/active_support/core_ext/date_time/calculations.rb
...ort/lib/active_support/core_ext/date_time/calculations.rb
+10
-0
activesupport/lib/active_support/core_ext/time/calculations.rb
...esupport/lib/active_support/core_ext/time/calculations.rb
+10
-0
activesupport/test/core_ext/date_ext_test.rb
activesupport/test/core_ext/date_ext_test.rb
+4
-0
activesupport/test/core_ext/date_time_ext_test.rb
activesupport/test/core_ext/date_time_ext_test.rb
+4
-0
activesupport/test/core_ext/time_ext_test.rb
activesupport/test/core_ext/time_ext_test.rb
+12
-0
未找到文件。
activesupport/lib/active_support/core_ext/date/calculations.rb
浏览文件 @
1b6bbb09
...
...
@@ -69,6 +69,16 @@ def beginning_of_day
alias
:at_midnight
:beginning_of_day
alias
:at_beginning_of_day
:beginning_of_day
# Converts Date to a Time (or DateTime if necessary) with the time portion set to the middle of the day (12:00)
def
middle_of_day
in_time_zone
.
middle_of_day
end
alias
:midday
:middle_of_day
alias
:noon
:middle_of_day
alias
:at_midday
:middle_of_day
alias
:at_noon
:middle_of_day
alias
:at_middle_of_day
:middle_of_day
# Converts Date to a Time (or DateTime if necessary) with the time portion set to the end of the day (23:59:59)
def
end_of_day
in_time_zone
.
end_of_day
...
...
@@ -119,7 +129,7 @@ def change(options)
options
.
fetch
(
:day
,
day
)
)
end
# Allow Date to be compared with Time by converting to DateTime and relying on the <=> from there.
def
compare_with_coercion
(
other
)
if
other
.
is_a?
(
Time
)
...
...
activesupport/lib/active_support/core_ext/date_time/calculations.rb
浏览文件 @
1b6bbb09
...
...
@@ -107,6 +107,16 @@ def beginning_of_day
alias
:at_midnight
:beginning_of_day
alias
:at_beginning_of_day
:beginning_of_day
# Returns a new DateTime representing the middle of the day (12:00)
def
middle_of_day
change
(
:hour
=>
12
)
end
alias
:midday
:middle_of_day
alias
:noon
:middle_of_day
alias
:at_midday
:middle_of_day
alias
:at_noon
:middle_of_day
alias
:at_middle_of_day
:middle_of_day
# Returns a new DateTime representing the end of the day (23:59:59).
def
end_of_day
change
(
:hour
=>
23
,
:min
=>
59
,
:sec
=>
59
)
...
...
activesupport/lib/active_support/core_ext/time/calculations.rb
浏览文件 @
1b6bbb09
...
...
@@ -161,6 +161,16 @@ def beginning_of_day
alias
:at_midnight
:beginning_of_day
alias
:at_beginning_of_day
:beginning_of_day
# Returns a new Time representing the middle of the day (12:00)
def
middle_of_day
change
(
:hour
=>
12
)
end
alias
:midday
:middle_of_day
alias
:noon
:middle_of_day
alias
:at_midday
:middle_of_day
alias
:at_noon
:middle_of_day
alias
:at_middle_of_day
:middle_of_day
# Returns a new Time representing the end of the day, 23:59:59.999999 (.999999999 in ruby1.9)
def
end_of_day
change
(
...
...
activesupport/test/core_ext/date_ext_test.rb
浏览文件 @
1b6bbb09
...
...
@@ -247,6 +247,10 @@ def test_beginning_of_day
assert_equal
Time
.
local
(
2005
,
2
,
21
,
0
,
0
,
0
),
Date
.
new
(
2005
,
2
,
21
).
beginning_of_day
end
def
test_middle_of_day
assert_equal
Time
.
local
(
2005
,
2
,
21
,
12
,
0
,
0
),
Date
.
new
(
2005
,
2
,
21
).
middle_of_day
end
def
test_beginning_of_day_when_zone_is_set
zone
=
ActiveSupport
::
TimeZone
[
'Eastern Time (US & Canada)'
]
with_env_tz
'UTC'
do
...
...
activesupport/test/core_ext/date_time_ext_test.rb
浏览文件 @
1b6bbb09
...
...
@@ -76,6 +76,10 @@ def test_beginning_of_day
assert_equal
DateTime
.
civil
(
2005
,
2
,
4
,
0
,
0
,
0
),
DateTime
.
civil
(
2005
,
2
,
4
,
10
,
10
,
10
).
beginning_of_day
end
def
test_middle_of_day
assert_equal
DateTime
.
civil
(
2005
,
2
,
4
,
12
,
0
,
0
),
DateTime
.
civil
(
2005
,
2
,
4
,
10
,
10
,
10
).
middle_of_day
end
def
test_end_of_day
assert_equal
DateTime
.
civil
(
2005
,
2
,
4
,
23
,
59
,
59
),
DateTime
.
civil
(
2005
,
2
,
4
,
10
,
10
,
10
).
end_of_day
end
...
...
activesupport/test/core_ext/time_ext_test.rb
浏览文件 @
1b6bbb09
...
...
@@ -117,6 +117,18 @@ def test_beginning_of_day
end
end
def
test_middle_of_day
assert_equal
Time
.
local
(
2005
,
2
,
4
,
12
,
0
,
0
),
Time
.
local
(
2005
,
2
,
4
,
10
,
10
,
10
).
middle_of_day
with_env_tz
'US/Eastern'
do
assert_equal
Time
.
local
(
2006
,
4
,
2
,
12
,
0
,
0
),
Time
.
local
(
2006
,
4
,
2
,
10
,
10
,
10
).
middle_of_day
,
'start DST'
assert_equal
Time
.
local
(
2006
,
10
,
29
,
12
,
0
,
0
),
Time
.
local
(
2006
,
10
,
29
,
10
,
10
,
10
).
middle_of_day
,
'ends DST'
end
with_env_tz
'NZ'
do
assert_equal
Time
.
local
(
2006
,
3
,
19
,
12
,
0
,
0
),
Time
.
local
(
2006
,
3
,
19
,
10
,
10
,
10
).
middle_of_day
,
'ends DST'
assert_equal
Time
.
local
(
2006
,
10
,
1
,
12
,
0
,
0
),
Time
.
local
(
2006
,
10
,
1
,
10
,
10
,
10
).
middle_of_day
,
'start DST'
end
end
def
test_beginning_of_hour
assert_equal
Time
.
local
(
2005
,
2
,
4
,
19
,
0
,
0
),
Time
.
local
(
2005
,
2
,
4
,
19
,
30
,
10
).
beginning_of_hour
end
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录