[ruby-core:74524] [Ruby trunk Feature#12211] introduce Date#first_of_month and Date#last_of_month

From: arai@...
Date: 2016-03-24 08:23:50 UTC
List: ruby-core #74524
Issue #12211 has been reported by Shunichi Arai.

----------------------------------------
Feature #12211: introduce Date#first_of_month and Date#last_of_month
https://bugs.ruby-lang.org/issues/12211

* Author: Shunichi Arai
* Status: Open
* Priority: Normal
* Assignee: 
----------------------------------------
Proposes new methods Date#first_of_month and Date#last_of_month which can be very helpful in reporting applications which need the first and the last day of a month very frequently.

~~~
class Date
    def first_of_month
      Date.new(year, month, 1)
    end
    def last_of_month
      next_month.first_of_month.prev_day
    end
end
~~~

Current way to do it `Date.new(date.year, date.month, 1)` is not elegant and short enough for this simple and common operation.




-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:[email protected]?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>

In This Thread

Prev Next