Sha256: fa8b700acf601b9936d381a6889352d7057570e2c13128a74998cd0378634609
Contents?: true
Size: 1.85 KB
Versions: 1
Compression:
Stored size: 1.85 KB
Contents
require 'increments/schedule/version' require 'holiday_japan' module Increments module Schedule extend self # rubocop:disable ModuleFunction def super_hanakin?(date) date.friday? && pay_day?(date) end def pay_day?(date) return work_day?(date) if date.day == 25 next_basic_pay_day = Date.new(date.year, date.month, 25) next_basic_pay_day = next_basic_pay_day.next_month if date > next_basic_pay_day date.next_day.upto(next_basic_pay_day).all? do |date_until_basic_pay_day| rest_day?(date_until_basic_pay_day) end end def work_day?(date) !rest_day?(date) end def office_work_day?(date) work_day?(date) && !remote_work_day?(date) end def remote_work_day?(date) normal_remote_work_day?(date) || special_remote_work_day?(date) end def normal_remote_work_day?(date) date.monday? && work_day?(date) end def special_remote_work_day?(date) normal_office_work_day?(date) && !normal_office_work_day?(date - 1) && !normal_office_work_day?(date + 1) end def rest_day?(date) weekend?(date) || holiday?(date) end def weekend?(date) date.saturday? || date.sunday? end def holiday?(date) HolidayJapan.check(date) end public_instance_methods.select { |name| name.to_s.end_with?('?') }.each do |predicate_method| enumeration_method = 'each_' + predicate_method.to_s.sub(/\?\z/, '') define_method(enumeration_method) do |max_date = nil, &block| return to_enum(__method__, max_date) unless block max_date ||= Date.today + 365 Date.today.upto(max_date) do |date| block.call(date) if send(predicate_method, date) end end end private def normal_office_work_day?(date) !rest_day?(date) && !normal_remote_work_day?(date) end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
increments-schedule-0.4.0 | lib/increments/schedule.rb |