Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
c9010561
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,发现更多精彩内容 >>
提交
c9010561
编写于
7月 29, 2013
作者:
A
Andrew White
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #10879 from makaroni4/master
Added Time#middle_of_day method
上级
b51786d2
1b6bbb09
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
50 addition
and
0 deletion
+50
-0
activesupport/lib/active_support/core_ext/date/calculations.rb
...esupport/lib/active_support/core_ext/date/calculations.rb
+10
-0
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
浏览文件 @
c9010561
...
...
@@ -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
...
...
activesupport/lib/active_support/core_ext/date_time/calculations.rb
浏览文件 @
c9010561
...
...
@@ -99,6 +99,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
浏览文件 @
c9010561
...
...
@@ -142,6 +142,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
浏览文件 @
c9010561
...
...
@@ -248,6 +248,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
浏览文件 @
c9010561
...
...
@@ -82,6 +82,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
浏览文件 @
c9010561
...
...
@@ -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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录