Skip to content

Instantly share code, notes, and snippets.

@romulostorel
Last active December 10, 2015 22:18
Show Gist options
  • Save romulostorel/4501708 to your computer and use it in GitHub Desktop.
Save romulostorel/4501708 to your computer and use it in GitHub Desktop.
require 'active_support/all'
from = "01/01/2012".to_date
to = "31/12/2012".to_date
tmp = from
count = 0
begin
tmp += 1.day
count += 1 unless tmp.saturday? || tmp.sunday?
end while tmp <= to
puts count
@fellix
Copy link

fellix commented Jan 10, 2013

require 'active_support/all'

from = "01/01/2012".to_date
to = "31/12/2012".to_date
days = (to - from).to_i
saturdays = (from..to).collect(&:saturday?).reject { |d| !d }.size
sundays = (from..to).collect(&:sunday?).reject { |d| !d }.size
days - sundays - saturdays

@fellix
Copy link

fellix commented Jan 10, 2013

from = "01/01/2012".to_date
to = "31/12/2012".to_date
days = (from..to).reject(&:sunday?).reject(&:saturday?).size

@fellix
Copy link

fellix commented Jan 10, 2013

from = "01/01/2012".to_date
to = "31/12/2012".to_date
days = (from..to).reject(&:sunday?).reject(&:saturday?).size

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment