Project

General

Profile

Actions

Feature #12211

open

introduce Date#first_of_month and Date#last_of_month

Added by araipiyo (Shunichi Arai) about 8 years ago. Updated about 8 years ago.

Status:
Open
Assignee:
-
Target version:
-
[ruby-core:74524]

Description

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.

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0