Permalink
Browse files

Simplify beginning_of_weekend method

  • Loading branch information...
1 parent 6395232 commit 4f8add5249f0f3c20e7fabbc93656a58e6a2dd59 @johnnyshields johnnyshields committed Jan 11, 2014
Showing with 3 additions and 11 deletions.
  1. +3 −11 lib/by_star/kernel/time.rb
View
14 lib/by_star/kernel/time.rb
@@ -3,18 +3,10 @@ module Kernel
module Time
# A "Weekend" is defined as the 60-hour period from 15:00 Friday to 03:00 Monday.
- # The weekend for a given date will be the the next weekend if the day Tues-Thurs,
- # otherwise the current/previous weekend if the day is Fri-Mon.
+ # The weekend for a given date will be the the next weekend if the day Mon-Thurs,
+ # otherwise the current weekend if the day is Fri-Sun.
def beginning_of_weekend
- friday = case self.wday
- when 0
- self.end_of_week.beginning_of_day.advance(:days => -2)
- when 5
- self.beginning_of_day
- else
- self.beginning_of_week.advance(:days => 4)
- end
- (friday + 15.hours)
+ beginning_of_week(:monday).advance(:days => 4) + 15.hours
end
def end_of_weekend

0 comments on commit 4f8add5

Please sign in to comment.