Reputation: 1
I've installed the Chronic gem and while
I can get Chronic.parse('Saturday', :context => :past) to return last Saturday's date but not
'5 last saturdays' returns 'nil'
I would like it to return in this format: strftime "%m%d%Y%H%M"
I also can't tag on any methods like .exists? or should ==true so I can use it to validate that those reports were run
I would just like to verify that 02/11/2017 02/04/2017 01/28/2017 01/28/2017 01/21/2017 appear as text on the page, but since they will change every week i need logic that will return last 5 Saturdays from now
Upvotes: 0
Views: 43
Reputation: 46836
Use "weeks ago" to get the Saturday of a previous week:
Chronic.parse('1 week ago Saturday')
#=> "2017-02-11 12:00:00 -0500"
Chronic.parse('2 weeks ago Saturday')
#=> "2017-02-04 12:00:00 -0500"
Chronic.parse('3 weeks ago Saturday')
#=> "2017-01-28 12:00:00 -0500"
Chronic.parse('4 weeks ago Saturday')
#=> "2017-01-21 12:00:00 -0500"
Chronic.parse('5 weeks ago Saturday')
#=> "2017-01-14 12:00:00 -0500"
You can format the value returned using #strftime
:
Chronic.parse('1 week ago Saturday').strftime("%m%d%Y%H%M")
#=> "021120171200"
Upvotes: 0