Created
December 5, 2017 12:14
-
-
Save harry-wood/537b8e9af3bf035db91c78af8e7b2b88 to your computer and use it in GitHub Desktop.
That thing when you write a ruby script to calculate holiday days :-)
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' | |
DAY_NAMES = %w[Sun Mon Tue Wed Thu Fri Sat].freeze | |
BANK_HOLIDAYS = [ | |
Date.new(2017, 1, 2), | |
Date.new(2017, 4, 14), | |
Date.new(2017, 4, 17), | |
Date.new(2017, 5, 1), | |
Date.new(2017, 5, 29), | |
Date.new(2017, 8, 28), | |
Date.new(2017, 12, 25), | |
Date.new(2017, 12, 26) | |
].freeze | |
working_days = 0 | |
tapi_days = 0 | |
days_to_oct = 0 | |
days_after_oct = 0 | |
no_thursdays = 0 | |
tues_wed = 0 | |
d = Date.new(2017, 1, 1) | |
while d < Date.new(2018, 1, 1) | |
d += 1 | |
next if d.wday == 0 || d.wday == 6 || (BANK_HOLIDAYS.include? d) | |
working_days += 1 | |
if d < Date.new(2017, 10, 1) | |
unless d.wday == 4 | |
tapi_days += 1 | |
days_to_oct += 1 | |
puts "#{working_days} - #{DAY_NAMES[d.wday]} - #{d}" | |
end | |
else | |
if d.wday == 2 || d.wday == 3 | |
tapi_days += 1 | |
days_after_oct += 1 | |
puts "#{working_days} - #{DAY_NAMES[d.wday]} - #{d}" | |
end | |
end | |
no_thursdays += 1 unless d.wday == 4 | |
tues_wed += 1 if d.wday == 2 || d.wday == 3 | |
end | |
puts "#{working_days} mon-fri working days" | |
puts "#{no_thursdays} no Thursdays" | |
puts "#{tues_wed} Tues & Wed" | |
puts "#{tapi_days} mon-wed+fri / tue-wed days" | |
puts "#{days_to_oct} mon-wed+fri days to oct" | |
puts "#{days_after_oct} tue-wed days days after oct" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment