Guest User

Untitled

a guest
Jan 22nd, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. require 'date'
  2.  
  3. def next_working_day(n = 1, from: Date.today)
  4. date = from
  5. i = 0
  6. while i < n
  7. i += 1 unless date.next_day.saturday? || date.next_day.sunday?
  8. date = date.next_day
  9. end
  10. date
  11. end
  12.  
  13. p next_working_day
  14. p next_working_day(from: Date.today)
  15. p next_working_day(1, from: Date.today)
  16. p next_working_day(2, from: Date.today)
  17. p next_working_day(3, from: Date.today)
  18. p next_working_day(4, from: Date.today)
  19. p next_working_day(5, from: Date.today)
  20. p next_working_day(6, from: Date.today)
  21. p next_working_day(7, from: Date.today)
  22.  
  23. p '---'
  24.  
  25. d = Date.today
  26. p "before #{d}"
  27. p next_working_day(from: d)
  28. p "after #{d}"
Add Comment
Please, Sign In to add comment