How to extract weekend days and working days from Date in Ruby?

week = Date.new(2017, 7, 24)..Date.new(2017, 7, 30)
weekend, working = week.partition{ |d| d.saturday? || d.sunday? }
weekend => [#<Date: 2017-07-29>, #<Date: 2017-07-30>]
working => [#<Date: 2017-07-24>, #<Date: 2017-07-25>, #<Date: 2017-07-26>, #<Date: 2017-07-27>, #<Date: 2017-07-28>]
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s