Finding the middle day of a month, given any day within that month Given a date, need to find the middle day of that day's month, or if there are an even number of days (with no exact middle day), the day should be the closest day to the middle of the month on the second half of the month.

For example, if the date given is August 2 (a month with 31 days), the middle day returned should be Aug 16.
If the date given is September 28 (a month with 30 days), the middle date returned should be 16 (15 would be closest day to middle in first half of month, 16 would be closest day to middle in second half of month).

Here's the code. Any better way to accomplish this with only version 2.4 and higher standard library and core?

#ruby 2.4.2
#require 'date'
def middleOfMonth(d)
  advancedMonth = d.next_month
  lastDayOfPreviousMonth = (Date.new(advancedMonth.year, advancedMonth.month, 1) - 1).day
  exactMiddle = lastDayOfPreviousMonth.to_f / 2
  actualMiddle = exactMiddle.floor + 1
  actualMiddle
end
Since February is the only month where the middle is 15 you could just write

d.month == 2 ? 15 : 16