Skip to content

Commit

Permalink
Revert "API-27078-526-v2-allow-yyyy-mm-date-format-2 (#12927)" (#12949)
Browse files Browse the repository at this point in the history
This reverts commit ae4f586.
  • Loading branch information
rmtolmach authored Jun 9, 2023
1 parent 48726b2 commit 06b7066
Show file tree
Hide file tree
Showing 9 changed files with 1,289 additions and 1,549 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ def validate_form_526_disability_approximate_begin_date!
approx_begin_date = disability['approximateDate']
next if approx_begin_date.blank?

next if date_is_valid_against_current_time_after_check_on_format?(approx_begin_date)
next if Date.parse(approx_begin_date) < Time.zone.today

raise ::Common::Exceptions::InvalidFieldValue.new('disability.approximateDate', approx_begin_date)
end
Expand Down Expand Up @@ -245,7 +245,7 @@ def validate_form_526_disability_secondary_disability_classification_code_matche
end

def validate_form_526_disability_secondary_disability_approximate_begin_date!(secondary_disability)
return if date_is_valid_against_current_time_after_check_on_format?(secondary_disability['approximateDate'])
return if Date.parse(secondary_disability['approximateDate']) < Time.zone.today

raise ::Common::Exceptions::InvalidFieldValue.new(
'disabilities.secondaryDisabilities.approximateDate',
Expand Down Expand Up @@ -368,7 +368,7 @@ def validate_form_526_separation_pay_received_date!
'datePaymentReceived')
return if separation_pay_received_date.blank?

return if date_is_valid_against_current_time_after_check_on_format?(separation_pay_received_date)
return if Date.parse(separation_pay_received_date) < Time.zone.today

raise ::Common::Exceptions::InvalidFieldValue.new('separationSeverancePay.datePaymentReceived',
separation_pay_received_date)
Expand Down Expand Up @@ -468,8 +468,7 @@ def validate_confinements!
service_information['confinements'].each do |confinement|
approximate_begin_date = confinement['approximateBeginDate']
approximate_end_date = confinement['approximateEndDate']

if begin_date_is_not_after_end_date?(approximate_begin_date, approximate_end_date)
if Date.parse(approximate_begin_date) > Date.parse(approximate_end_date)
raise ::Common::Exceptions::UnprocessableEntity.new(
detail: 'Approximate end date must be after approximate begin date.'
)
Expand Down Expand Up @@ -577,55 +576,6 @@ def raise_exception_if_value_present(val)
detail: "The #{val} is required for direct deposit."
)
end

private

def begin_date_is_not_after_end_date?(begin_date, end_date)
# see what format each date is in
begin_date_has_day = date_has_day?(begin_date)
end_date_has_day = date_has_day?(end_date)
# determine how to compare, being = is ok
if (begin_date_has_day && end_date_has_day) || (!begin_date_has_day && !end_date_has_day) # same format
begin_date > end_date
else # mixed formats on dates
begin_date_not_after_end_date_with_mixed_format_dates?(begin_date, end_date)
end
end

# Either date could be in MM-YYYY or MM-DD-YYYY format
def begin_date_not_after_end_date_with_mixed_format_dates?(begin_date, end_date)
# figure out which one has the day and remove it
if date_has_day?(begin_date)
begin_date = remove_chars(begin_date.dup)
elsif date_has_day?(end_date)
end_date = remove_chars(end_date.dup)
end
Date.strptime(begin_date, '%m-%Y') > Date.strptime(end_date, '%m-%Y') # = is ok
end

def date_is_valid_against_current_time_after_check_on_format?(date)
if date_has_day?(date)
param_date = Date.strptime(date, '%m-%d-%Y')
now_date = Date.strptime(Time.zone.today.strftime('%m-%d-%Y'), '%m-%d-%Y')
else
param_date = Date.strptime(date, '%m-%Y')
now_date = Date.strptime(Time.zone.today.strftime('%m-%Y'), '%m-%Y')
end
param_date <= now_date # Since it is approximate we go with <=
end

# just need to know if day is present or not
def date_has_day?(date)
date.length == 10
end

# making date approximate to compare
def remove_chars(str)
indices = [2, 3, 4] # MM| -DD |-YYYY
sz = str.size
indices.map { |i| i >= 0 ? i : sz + i }.sort.reverse_each { |i| str[i] = '' }
str
end
end
end
end
257 changes: 139 additions & 118 deletions modules/claims_api/app/swagger/claims_api/v2/dev/swagger.json

Large diffs are not rendered by default.

Loading

0 comments on commit 06b7066

Please sign in to comment.