Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
6f380d37
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,发现更多精彩内容 >>
提交
6f380d37
编写于
2月 21, 2013
作者:
G
Gagan Awhad
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Added beginning_of_minute support to core_ext calculations for Time and DateTime
上级
38939795
变更
6
显示空白变更内容
内联
并排
Showing
6 changed file
with
61 addition
and
0 deletion
+61
-0
activesupport/CHANGELOG.md
activesupport/CHANGELOG.md
+4
-0
activesupport/lib/active_support/core_ext/date_time/calculations.rb
...ort/lib/active_support/core_ext/date_time/calculations.rb
+12
-0
activesupport/lib/active_support/core_ext/time/calculations.rb
...esupport/lib/active_support/core_ext/time/calculations.rb
+15
-0
activesupport/test/core_ext/date_time_ext_test.rb
activesupport/test/core_ext/date_time_ext_test.rb
+8
-0
activesupport/test/core_ext/time_ext_test.rb
activesupport/test/core_ext/time_ext_test.rb
+8
-0
activesupport/test/core_ext/time_with_zone_test.rb
activesupport/test/core_ext/time_with_zone_test.rb
+14
-0
未找到文件。
activesupport/CHANGELOG.md
浏览文件 @
6f380d37
## Rails 4.0.0 (unreleased) ##
*
Added beginning_of_minute support to core_ext calculations for Time and DateTime
*Gagan Awhad*
*
Add
`:nsec`
date format.
*Jamie Gaskins*
...
...
activesupport/lib/active_support/core_ext/date_time/calculations.rb
浏览文件 @
6f380d37
...
...
@@ -124,6 +124,18 @@ def end_of_hour
end
alias
:at_end_of_hour
:end_of_hour
# Returns a new DateTime representing the start of the hour (hh:mm:00).
def
beginning_of_minute
change
(
:sec
=>
0
)
end
alias
:at_beginning_of_minute
:beginning_of_minute
# Returns a new DateTime representing the end of the minute (hh:mm:59).
def
end_of_minute
change
(
:sec
=>
59
)
end
alias
:at_end_of_minute
:end_of_minute
# Adjusts DateTime to UTC by adding its offset value; offset is set to 0.
#
# DateTime.civil(2005, 2, 21, 10, 11, 12, Rational(-6, 24)) # => Mon, 21 Feb 2005 10:11:12 -0600
...
...
activesupport/lib/active_support/core_ext/time/calculations.rb
浏览文件 @
6f380d37
...
...
@@ -188,6 +188,21 @@ def end_of_hour
end
alias
:at_end_of_hour
:end_of_hour
# Returns a new Time representing the start of the hour (x:xx:00)
def
beginning_of_minute
change
(
:sec
=>
0
)
end
alias
:at_beginning_of_minute
:beginning_of_minute
# Returns a new Time representing the end of the hour, x:59:59.999999 (.999999999 in ruby1.9)
def
end_of_minute
change
(
:sec
=>
59
,
:usec
=>
Rational
(
999999999
,
1000
)
)
end
alias
:at_end_of_minute
:end_of_minute
# Returns a Range representing the whole day of the current time.
def
all_day
beginning_of_day
..
end_of_day
...
...
activesupport/test/core_ext/date_time_ext_test.rb
浏览文件 @
6f380d37
...
...
@@ -88,6 +88,14 @@ def test_end_of_hour
assert_equal
DateTime
.
civil
(
2005
,
2
,
4
,
19
,
59
,
59
),
DateTime
.
civil
(
2005
,
2
,
4
,
19
,
30
,
10
).
end_of_hour
end
def
test_beginning_of_minute
assert_equal
DateTime
.
civil
(
2005
,
2
,
4
,
19
,
30
,
0
),
DateTime
.
civil
(
2005
,
2
,
4
,
19
,
30
,
10
).
beginning_of_minute
end
def
test_end_of_minute
assert_equal
DateTime
.
civil
(
2005
,
2
,
4
,
19
,
30
,
59
),
DateTime
.
civil
(
2005
,
2
,
4
,
19
,
30
,
10
).
end_of_minute
end
def
test_end_of_month
assert_equal
DateTime
.
civil
(
2005
,
3
,
31
,
23
,
59
,
59
),
DateTime
.
civil
(
2005
,
3
,
20
,
10
,
10
,
10
).
end_of_month
assert_equal
DateTime
.
civil
(
2005
,
2
,
28
,
23
,
59
,
59
),
DateTime
.
civil
(
2005
,
2
,
20
,
10
,
10
,
10
).
end_of_month
...
...
activesupport/test/core_ext/time_ext_test.rb
浏览文件 @
6f380d37
...
...
@@ -121,6 +121,10 @@ 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
def
test_beginning_of_minute
assert_equal
Time
.
local
(
2005
,
2
,
4
,
19
,
30
,
0
),
Time
.
local
(
2005
,
2
,
4
,
19
,
30
,
10
).
beginning_of_minute
end
def
test_end_of_day
assert_equal
Time
.
local
(
2007
,
8
,
12
,
23
,
59
,
59
,
Rational
(
999999999
,
1000
)),
Time
.
local
(
2007
,
8
,
12
,
10
,
10
,
10
).
end_of_day
with_env_tz
'US/Eastern'
do
...
...
@@ -137,6 +141,10 @@ def test_end_of_hour
assert_equal
Time
.
local
(
2005
,
2
,
4
,
19
,
59
,
59
,
Rational
(
999999999
,
1000
)),
Time
.
local
(
2005
,
2
,
4
,
19
,
30
,
10
).
end_of_hour
end
def
test_end_of_minute
assert_equal
Time
.
local
(
2005
,
2
,
4
,
19
,
30
,
59
,
Rational
(
999999999
,
1000
)),
Time
.
local
(
2005
,
2
,
4
,
19
,
30
,
10
).
end_of_minute
end
def
test_last_year
assert_equal
Time
.
local
(
2004
,
6
,
5
,
10
),
Time
.
local
(
2005
,
6
,
5
,
10
,
0
,
0
).
last_year
end
...
...
activesupport/test/core_ext/time_with_zone_test.rb
浏览文件 @
6f380d37
...
...
@@ -539,6 +539,20 @@ def test_end_of_hour
assert_equal
"Fri, 31 Dec 1999 19:59:59 EST -05:00"
,
twz
.
end_of_hour
.
inspect
end
def
test_beginning_of_minute
utc
=
Time
.
utc
(
2000
,
1
,
1
,
0
,
30
,
10
)
twz
=
ActiveSupport
::
TimeWithZone
.
new
(
utc
,
@time_zone
)
assert_equal
"Fri, 31 Dec 1999 19:30:10 EST -05:00"
,
twz
.
inspect
assert_equal
"Fri, 31 Dec 1999 19:00:00 EST -05:00"
,
twz
.
beginning_of_hour
.
inspect
end
def
test_end_of_minute
utc
=
Time
.
utc
(
2000
,
1
,
1
,
0
,
30
,
10
)
twz
=
ActiveSupport
::
TimeWithZone
.
new
(
utc
,
@time_zone
)
assert_equal
"Fri, 31 Dec 1999 19:30:10 EST -05:00"
,
twz
.
inspect
assert_equal
"Fri, 31 Dec 1999 19:30:59 EST -05:00"
,
twz
.
end_of_minute
.
inspect
end
def
test_since
assert_equal
"Fri, 31 Dec 1999 19:00:01 EST -05:00"
,
@twz
.
since
(
1
).
inspect
end
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录