Created
August 20, 2015 22:30
-
-
Save rhydlewis/e8f4def2d845822d4597 to your computer and use it in GitHub Desktop.
Network days function (ruby)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'date' | |
def network_days(start_date, end_date) | |
days_between = (end_date - start_date).to_i | |
whole_weeks, extra_days = days_between.divmod(7) | |
unless extra_days.zero? | |
extra_days -= if (start_date + 1).wday <= end_date.wday | |
[(start_date + 1).sunday?, end_date.saturday?].count(true) | |
else | |
2 | |
end | |
end | |
(whole_weeks * 5) + extra_days + 1 | |
end | |
start_date = Date.new(2015,07,13) | |
end_date = Date.new(2015,07,20) | |
puts network_days(start_date, end_date) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment