mirror of
https://github.com/github/rails.git
synced 2026-04-26 03:00:59 -04:00
Convert aliases monday and sunday to methods
A recent change to beginning_of_week and end_of_week added an argument that can be used to specify the week's starting day as a symbol. Now these methods were aliased as monday and sunday respectively which as a consequence of the argument addition, made calls like obj.monday(:sunday) possible. This commit makes them methods on their own.
This commit is contained in:
@@ -190,9 +190,14 @@ class Date
|
||||
result = self - days_to_start
|
||||
acts_like?(:time) ? result.midnight : result
|
||||
end
|
||||
alias :monday :beginning_of_week
|
||||
alias :at_beginning_of_week :beginning_of_week
|
||||
|
||||
# Returns a new +Date+/+DateTime+ representing the start of this week. Week is
|
||||
# assumed to start on a Monday. +DateTime+ objects have their time set to 0:00.
|
||||
def monday
|
||||
beginning_of_week
|
||||
end
|
||||
|
||||
# Returns a new +Date+/+DateTime+ representing the end of this week. Week is
|
||||
# assumed to start on +start_day+, default is +:monday+. +DateTime+ objects
|
||||
# have their time set to 23:59:59.
|
||||
@@ -201,9 +206,14 @@ class Date
|
||||
result = self + days_to_end.days
|
||||
self.acts_like?(:time) ? result.end_of_day : result
|
||||
end
|
||||
alias :sunday :end_of_week
|
||||
alias :at_end_of_week :end_of_week
|
||||
|
||||
# Returns a new +Date+/+DateTime+ representing the end of this week. Week is
|
||||
# assumed to start on a Monday. +DateTime+ objects have their time set to 23:59:59.
|
||||
def sunday
|
||||
end_of_week
|
||||
end
|
||||
|
||||
# Returns a new +Date+/+DateTime+ representing the given +day+ in the previous
|
||||
# week. Default is +:monday+. +DateTime+ objects have their time set to 0:00.
|
||||
def prev_week(day = :monday)
|
||||
|
||||
@@ -174,9 +174,14 @@ class Time
|
||||
days_to_start = days_to_week_start(start_day)
|
||||
(self - days_to_start.days).midnight
|
||||
end
|
||||
alias :monday :beginning_of_week
|
||||
alias :at_beginning_of_week :beginning_of_week
|
||||
|
||||
# Returns a new +Date+/+DateTime+ representing the start of this week. Week is
|
||||
# assumed to start on a Monday. +DateTime+ objects have their time set to 0:00.
|
||||
def monday
|
||||
beginning_of_week
|
||||
end
|
||||
|
||||
# Returns a new Time representing the end of this week, week starts on start_day (default is :monday, i.e. end of Sunday).
|
||||
def end_of_week(start_day = :monday)
|
||||
days_to_end = 6 - days_to_week_start(start_day)
|
||||
|
||||
@@ -3051,7 +3051,7 @@ d.end_of_week # => Sun, 09 May 2010
|
||||
d.end_of_week(:sunday) # => Sat, 08 May 2010
|
||||
</ruby>
|
||||
|
||||
+beginning_of_week+ is aliased to +monday+ and +at_beginning_of_week+. +end_of_week+ is aliased to +sunday+ and +at_end_of_week+.
|
||||
+beginning_of_week+ is aliased to +at_beginning_of_week+ and +end_of_week+ is aliased to +at_end_of_week+.
|
||||
|
||||
h6. +prev_week+, +next_week+
|
||||
|
||||
@@ -3276,8 +3276,10 @@ The class +DateTime+ is a subclass of +Date+ so by loading +active_support/core_
|
||||
<ruby>
|
||||
yesterday
|
||||
tomorrow
|
||||
beginning_of_week (monday, at_beginning_of_week)
|
||||
beginning_of_week (at_beginning_of_week)
|
||||
end_of_week (at_end_of_week)
|
||||
monday
|
||||
sunday
|
||||
weeks_ago
|
||||
prev_week
|
||||
next_week
|
||||
@@ -3450,8 +3452,9 @@ ago
|
||||
since (in)
|
||||
beginning_of_day (midnight, at_midnight, at_beginning_of_day)
|
||||
end_of_day
|
||||
beginning_of_week (monday, at_beginning_of_week)
|
||||
beginning_of_week (at_beginning_of_week)
|
||||
end_of_week (at_end_of_week)
|
||||
monday
|
||||
weeks_ago
|
||||
prev_week
|
||||
next_week
|
||||
|
||||
Reference in New Issue
Block a user