module ActiveSupport::CoreExtensions::Time::Calculations::ClassMethods

def ===(other)

Overriding case equality method so that it returns true for ActiveSupport::TimeWithZone instances
def ===(other)
  other.is_a?(::Time)
end

def days_in_month(month, year = now.year)

If no year is specified, it will use the current year.
Return the number of days in the given month.
def days_in_month(month, year = now.year)
  return 29 if month == 2 && ::Date.gregorian_leap?(year)
  COMMON_YEAR_DAYS_IN_MONTH[month]
end

def local_time(*args)

Wraps class method +time_with_datetime_fallback+ with +utc_or_local+ set to :local.
def local_time(*args)
  time_with_datetime_fallback(:local, *args)
end

def time_with_datetime_fallback(utc_or_local, year, month=1, day=1, hour=0, min=0, sec=0, usec=0)

otherwise returns a DateTime
(i.e., if year is within either 1970..2038 or 1902..2038, depending on system architecture);
Returns a new Time if requested year can be accommodated by Ruby's Time class
def time_with_datetime_fallback(utc_or_local, year, month=1, day=1, hour=0, min=0, sec=0, usec=0)
  ::Time.send(utc_or_local, year, month, day, hour, min, sec, usec)
rescue
  offset = utc_or_local.to_sym == :local ? ::DateTime.local_offset : 0
  ::DateTime.civil(year, month, day, hour, min, sec, offset)
end

def utc_time(*args)

Wraps class method +time_with_datetime_fallback+ with +utc_or_local+ set to :utc.
def utc_time(*args)
  time_with_datetime_fallback(:utc, *args)
end