Skip to content

Instantly share code, notes, and snippets.

@samir
Created September 1, 2014 20:33
Show Gist options
  • Save samir/fe02a7124c2e7add6742 to your computer and use it in GitHub Desktop.
Save samir/fe02a7124c2e7add6742 to your computer and use it in GitHub Desktop.

Revisions

  1. samir created this gist Sep 1, 2014.
    18 changes: 18 additions & 0 deletions date_time.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,18 @@
    module BusinessDay
    def next_business_day
    self.skip_weekends self, 1
    end
    def previous_business_day
    self.skip_weekends self, -1
    end
    protected
    def skip_weekends(date, inc)
    date += inc
    while (date.wday % 7 == 0) or (date.wday % 7 == 6) do
    date += inc
    end
    date
    end
    end

    Date.send :include, BusinessDay