user12763413
user12763413

Reputation: 1347

Chronic not selecting correct 1st monday of the month

def monday?
  require 'chronic'
  today = Date.today
  1st_monday = Chronic.parse('1st monday of this month', now: today.beginning_of_month).to_date
  3rd_monday = Chronic.parse('3th monday of this month', now: today.beginning_of_month).to_date
  return today == 1st_monday || today == 3rd_monday
end

I have defined this method to select the first or third monday of each month. The issue arose today as Chronic selected June 8th as the first monday of the month which is wrong as June 1st was the first monday. Any idea how this issue can be resolved? Could it be because we have five mondays this month which confused Chronic?

Upvotes: 2

Views: 103

Answers (1)

lacostenycoder
lacostenycoder

Reputation: 11216

Seems to be a bug in the Chronic gem. Guess you'll have to go with this solution:

month = Date.today.strftime('%B')
=>"June"

Chronic.parse("3st monday of this #{month}")

=> 2020-06-15 12:00:00 -0400

Upvotes: -1

Related Questions