Sha256: 2c78a93d4dc828350f7d0aa85241a4e883b8e9563c7a85dc8128696a750a537c
Contents?: true
Size: 1.28 KB
Versions: 67
Compression:
Stored size: 1.28 KB
Contents
module Users class DateJumperController < PgEngine.config.users_controller before_action only: :jump do if params[:quantity].blank? raise PgEngine::BadUserInput, 'Cantidad incorrecta' end end def jump start_date = Date.parse(params[:start_date]) quantity = params[:quantity].to_i date = case params[:type] when 'calendar_days' start_date + (multiplier * quantity.days) when 'business_days', 'business_days_excluding_holidays' resolve_business_days(start_date, quantity) when 'weeks' start_date + (multiplier * quantity.weeks) when 'months' start_date + (multiplier * quantity.months) else # :nocov: raise PgEngine::Error, 'type no soportado' # :nocov: end render json: { date: } end private def resolve_business_days(start_date, quantity) exclude_holidays = params[:type].include?('excluding_holidays') options = { direction: params[:direction], exclude_holidays: } PgEngine::DateJumper.new(start_date) .business_days(quantity, **options) end def multiplier if params[:direction] == 'forward' 1 else -1 end end end end
Version data entries
67 entries across 67 versions & 1 rubygems