Module | ActiveSupport::CoreExtensions::Time::Calculations::ClassMethods |
In: |
vendor/rails/activesupport/lib/active_support/core_ext/time/calculations.rb
|
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.
# File vendor/rails/activesupport/lib/active_support/core_ext/time/calculations.rb, line 22 22: def days_in_month(month, year=nil) 23: if month == 2 24: !year.nil? && (year % 4 == 0) && ((year % 100 != 0) || (year % 400 == 0)) ? 29 : 28 25: elsif month <= 7 26: month % 2 == 0 ? 30 : 31 27: else 28: month % 2 == 0 ? 31 : 30 29: end 30: end
wraps class method time_with_datetime_fallback with utc_or_local == :local
# File vendor/rails/activesupport/lib/active_support/core_ext/time/calculations.rb, line 48 48: def local_time(*args) 49: time_with_datetime_fallback(:local, *args) 50: end
Returns a new Time if requested year can be accommodated by Ruby‘s Time class (i.e., if year is within either 1970..2038 or 1902..2038, depending on system architecture); otherwise returns a DateTime
# File vendor/rails/activesupport/lib/active_support/core_ext/time/calculations.rb, line 35 35: def time_with_datetime_fallback(utc_or_local, year, month=1, day=1, hour=0, min=0, sec=0, usec=0) 36: ::Time.send(utc_or_local, year, month, day, hour, min, sec, usec) 37: rescue 38: offset = utc_or_local.to_sym == :local ? ::DateTime.local_offset : 0 39: ::DateTime.civil(year, month, day, hour, min, sec, offset) 40: end
wraps class method time_with_datetime_fallback with utc_or_local == :utc
# File vendor/rails/activesupport/lib/active_support/core_ext/time/calculations.rb, line 43 43: def utc_time(*args) 44: time_with_datetime_fallback(:utc, *args) 45: end