@@ -92,33 +92,58 @@ def years_since(years)
92
92
end
93
93
94
94
# Returns a new date/time at the start of the month.
95
- # DateTime objects will have a time set to 0:00.
95
+ #
96
+ # today = Date.today # => Thu, 18 Jun 2015
97
+ # today.beginning_of_month # => Mon, 01 Jun 2015
98
+ #
99
+ # +DateTime+ objects will have a time set to 0:00.
100
+ #
101
+ # now = DateTime.current # => Thu, 18 Jun 2015 15:23:13 +0000
102
+ # now.beginning_of_month # => Mon, 01 Jun 2015 00:00:00 +0000
96
103
def beginning_of_month
97
104
first_hour ( change ( :day => 1 ) )
98
105
end
99
106
alias :at_beginning_of_month :beginning_of_month
100
107
101
108
# Returns a new date/time at the start of the quarter.
102
- # Example: 1st January, 1st July, 1st October.
103
- # DateTime objects will have a time set to 0:00.
109
+ #
110
+ # today = Date.today # => Fri, 10 Jul 2015
111
+ # today.beginning_of_quarter # => Wed, 01 Jul 2015
112
+ #
113
+ # +DateTime+ objects will have a time set to 0:00.
114
+ #
115
+ # now = DateTime.current # => Fri, 10 Jul 2015 18:41:29 +0000
116
+ # now.beginning_of_quarter # => Wed, 01 Jul 2015 00:00:00 +0000
104
117
def beginning_of_quarter
105
118
first_quarter_month = [ 10 , 7 , 4 , 1 ] . detect { |m | m <= month }
106
119
beginning_of_month . change ( :month => first_quarter_month )
107
120
end
108
121
alias :at_beginning_of_quarter :beginning_of_quarter
109
122
110
123
# Returns a new date/time at the end of the quarter.
111
- # Example: 31st March, 30th June, 30th September.
112
- # DateTime objects will have a time set to 23:59:59.
124
+ #
125
+ # today = Date.today # => Fri, 10 Jul 2015
126
+ # today.end_of_quarter # => Wed, 30 Sep 2015
127
+ #
128
+ # +DateTime+ objects will have a time set to 23:59:59.
129
+ #
130
+ # now = DateTime.current # => Fri, 10 Jul 2015 18:41:29 +0000
131
+ # now.end_of_quarter # => Wed, 30 Sep 2015 23:59:59 +0000
113
132
def end_of_quarter
114
133
last_quarter_month = [ 3 , 6 , 9 , 12 ] . detect { |m | m >= month }
115
134
beginning_of_month . change ( :month => last_quarter_month ) . end_of_month
116
135
end
117
136
alias :at_end_of_quarter :end_of_quarter
118
137
119
138
# Return a new date/time at the beginning of the year.
120
- # Example: 1st January.
121
- # DateTime objects will have a time set to 0:00.
139
+ #
140
+ # today = Date.today # => Fri, 10 Jul 2015
141
+ # today.beginning_of_year # => Thu, 01 Jan 2015
142
+ #
143
+ # +DateTime+ objects will have a time set to 0:00.
144
+ #
145
+ # now = DateTime.current # => Fri, 10 Jul 2015 18:41:29 +0000
146
+ # now.beginning_of_year # => Thu, 01 Jan 2015 00:00:00 +0000
122
147
def beginning_of_year
123
148
change ( :month => 1 ) . beginning_of_month
124
149
end
@@ -138,8 +163,8 @@ def beginning_of_year
138
163
#
139
164
# +DateTime+ objects have their time set to 0:00 unless +same_time+ is true.
140
165
#
141
- # now = Time .current # => Thu, 07 May 2015 13:31:16 UTC +00:00
142
- # now.next_week # => Mon, 11 May 2015 00:00:00 UTC +00:00
166
+ # now = DateTime .current # => Thu, 07 May 2015 13:31:16 +0000
167
+ # now.next_week # => Mon, 11 May 2015 00:00:00 +0000
143
168
def next_week ( given_day_in_next_week = Date . beginning_of_week , same_time : false )
144
169
result = first_hour ( weeks_since ( 1 ) . beginning_of_week . days_since ( days_span ( given_day_in_next_week ) ) )
145
170
same_time ? copy_time_to ( result ) : result
0 commit comments