Module: ActiveSupport::CoreExtensions::Time::Calculations::ClassMethods
- Defined in:
- lib/active_support/core_ext/time/calculations.rb
Instance Method Summary collapse
-
#days_in_month(month, year = nil) ⇒ Object
Return the number of days in the given month.
Instance Method Details
#days_in_month(month, year = nil) ⇒ Object
Return the number of days in the given month. If a year is given, February will return the correct number of days for leap years. Otherwise, this method will always report February as having 28 days.
15 16 17 18 19 20 21 22 23 |
# File 'lib/active_support/core_ext/time/calculations.rb', line 15 def days_in_month(month, year=nil) if month == 2 !year.nil? && (year % 4 == 0) && ((year % 100 != 0) || (year % 400 == 0)) ? 29 : 28 elsif month <= 7 month % 2 == 0 ? 30 : 31 else month % 2 == 0 ? 31 : 30 end end |