Module: CalendarChina::Methods
- Included in:
- Date
- Defined in:
- lib/calendar_china/methods.rb
Instance Method Summary collapse
- #is_holiday?(date = china_date) ⇒ Boolean
- #is_rest?(date = china_date) ⇒ Boolean
- #is_workday?(date = china_date) ⇒ Boolean
- #next_workday(date = china_date) ⇒ Object
Instance Method Details
#is_holiday?(date = china_date) ⇒ Boolean
3 4 5 |
# File 'lib/calendar_china/methods.rb', line 3 def is_holiday?(date = china_date) holidays.include?(date) end |
#is_rest?(date = china_date) ⇒ Boolean
11 12 13 |
# File 'lib/calendar_china/methods.rb', line 11 def is_rest?(date = china_date) !is_workday?(date) end |
#is_workday?(date = china_date) ⇒ Boolean
7 8 9 |
# File 'lib/calendar_china/methods.rb', line 7 def is_workday?(date = china_date) special_work_days.include?(date) || !(is_holiday?(date) || date.to_date.on_weekend?) end |
#next_workday(date = china_date) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/calendar_china/methods.rb', line 15 def next_workday(date = china_date) result = {} st = date.to_date.deep_dup current_date = date.to_date loop do next_date = current_date.next date_str = format_date(next_date) if is_workday?(date_str) days = (next_date - st).to_i result[:date] = date_str result[:days] = days - 1 break else current_date = next_date end end result end |