Module: RailsBookingTime
- Extended by:
- ActiveSupport::Concern
- Defined in:
- app/models/rails_booking/concerns/the_booking_time.rb
Instance Method Summary collapse
- #deal_repeat_days ⇒ Object
- #extra ⇒ Object
- #next_day(datetime) ⇒ Object
- #next_finish_at ⇒ Object
- #next_finish_time ⇒ Object
- #next_start_at ⇒ Object
- #next_start_time ⇒ Object
- #validate_finish_at ⇒ Object
Instance Method Details
#deal_repeat_days ⇒ Object
33 34 35 |
# File 'app/models/rails_booking/concerns/the_booking_time.rb', line 33 def deal_repeat_days self.repeat_days = self.repeat_days.map(&:to_i) end |
#extra ⇒ Object
37 38 39 |
# File 'app/models/rails_booking/concerns/the_booking_time.rb', line 37 def extra {} end |
#next_day(datetime) ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'app/models/rails_booking/concerns/the_booking_time.rb', line 75 def next_day(datetime) start_at_date = self.start_at.change(year: datetime.year, month: datetime.month, day: datetime.day) if start_at_date > datetime if self.repeat_type == 'week' next_days = self.repeat_days.select { |day| day >= datetime.days_to_week_start } else #if self.repeat_type == 'month' next_days = self.repeat_days.select { |day| day >= datetime.day } end else next_days = self.repeat_days.select { |day| day > datetime.day } end if next_days.size > 0 if self.repeat_type == 'week' days_span = next_days[0] - datetime.days_to_week_start day = datetime.beginning_of_week.days_since(days_span) month = day.month min = day.day else month = datetime.month min = next_days[0] end next_day = datetime.change(month: month, day: min) else if self.repeat_type == 'week' str = Date::DAYS_INTO_WEEK.key(self.repeat_days.min) day = datetime.next_week(str) month = day.month min = day.day else month = datetime.next_month.month min = self.repeat_days.min end next_day = datetime.change(month: month, day: min) end next_day end |
#next_finish_at ⇒ Object
69 70 71 72 73 |
# File 'app/models/rails_booking/concerns/the_booking_time.rb', line 69 def next_finish_at return if finish_at.nil? _next_day = self.next_day(Time.now) _next_day.change(hour: finish_at.hour, min: finish_at.min, sec: finish_at.sec) end |
#next_finish_time ⇒ Object
52 53 54 55 56 57 58 59 60 61 |
# File 'app/models/rails_booking/concerns/the_booking_time.rb', line 52 def next_finish_time if finish_at.nil? return finish_at end if self.once? self.finish_at else self.next_finish_at end end |
#next_start_at ⇒ Object
63 64 65 66 67 |
# File 'app/models/rails_booking/concerns/the_booking_time.rb', line 63 def next_start_at return if start_at.nil? _next_day = self.next_day(Time.now) _next_day.change(hour: start_at.hour, min: start_at.min, sec: start_at.sec) end |
#next_start_time ⇒ Object
41 42 43 44 45 46 47 48 49 50 |
# File 'app/models/rails_booking/concerns/the_booking_time.rb', line 41 def next_start_time if start_at.nil? return start_at end if self.once? self.start_at else self.next_start_at end end |
#validate_finish_at ⇒ Object
25 26 27 28 29 30 31 |
# File 'app/models/rails_booking/concerns/the_booking_time.rb', line 25 def validate_finish_at return unless self.respond_to?('finish_at') return if finish_at.nil? && start_at.nil? unless finish_at > start_at self.errors.add :finish_at, 'Finish At Should large then Start at time!' end end |