mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
better document next_week
functionaility closes #9568
This commit is contained in:
parent
d495606168
commit
888f21492a
2 changed files with 10 additions and 5 deletions
|
@ -109,11 +109,11 @@ module DateAndTime
|
|||
alias :at_beginning_of_year :beginning_of_year
|
||||
|
||||
# Returns a new date/time representing the given day in the next week.
|
||||
# Week is assumed to start on +start_day+, default is
|
||||
# +Date.beginning_of_week+ or +config.beginning_of_week+ when set.
|
||||
# DateTime objects have their time set to 0:00.
|
||||
def next_week(start_day = Date.beginning_of_week)
|
||||
first_hour{ weeks_since(1).beginning_of_week.days_since(days_span(start_day)) }
|
||||
# The +given_day_in_next_week+ defaults to the beginning of the week
|
||||
# which is determined by +Date.beginning_of_week+ or +config.beginning_of_week+
|
||||
# when set. DateTime objects have their time set to 0:00.
|
||||
def next_week(given_day_in_next_week = Date.beginning_of_week)
|
||||
first_hour{ weeks_since(1).beginning_of_week.days_since(days_span(given_day_in_next_week)) }
|
||||
end
|
||||
|
||||
# Short-hand for months_since(1).
|
||||
|
|
|
@ -95,6 +95,11 @@ module DateAndTimeBehavior
|
|||
end
|
||||
|
||||
def test_next_week
|
||||
# M | T | W | T | F | S | S # M | T | W | T | F | S | S #
|
||||
# | 22/2 | | | | | # 28/2 | | | | | | # monday in next week `next_week`
|
||||
# | 22/2 | | | | | # | | | | 4/3 | | # friday in next week `next_week(:friday)`
|
||||
# 23/10 | | | | | | # 30/10 | | | | | | # monday in next week `next_week`
|
||||
# 23/10 | | | | | | # | | 1/11 | | | | # wednesday in next week `next_week(:wednesday)`
|
||||
assert_equal date_time_init(2005,2,28,0,0,0), date_time_init(2005,2,22,15,15,10).next_week
|
||||
assert_equal date_time_init(2005,3,4,0,0,0), date_time_init(2005,2,22,15,15,10).next_week(:friday)
|
||||
assert_equal date_time_init(2006,10,30,0,0,0), date_time_init(2006,10,23,0,0,0).next_week
|
||||
|
|
Loading…
Reference in a new issue