Module: TimeBoss::Calendar::Support::Clampable
Instance Method Summary collapse
-
#clamp(unit) ⇒ Period
Clamp this unit to the range of the provided unit.
Instance Method Details
#clamp(unit) ⇒ Period
Clamp this unit to the range of the provided unit.
9 10 11 12 13 14 |
# File 'lib/timeboss/calendar/support/clampable.rb', line 9 def clamp(unit) new_start_date = start_date.clamp(unit.start_date, unit.end_date) new_end_date = end_date.clamp(unit.start_date, unit.end_date) return unless new_start_date.between?(start_date, end_date) && new_end_date.between?(start_date, end_date) calendar.parse("#{new_start_date}..#{new_end_date}") end |