Skip to content

Conversation

@chubchenko
Copy link
Contributor

Overview

In the previous release, the #stringify_with_same_day method was changed. After that, company_descriptive_date started having different formatting when creating the ACH file.

To prove that I have added a test and attached a screenshot below.

image

#strftime will return a string representation where #strptime is a `DateTime`.
Comment on lines +7 to 9
f.strftime('%y%m%d')
rescue
f
Copy link
Collaborator

@henriquegasques henriquegasques Mar 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for reporting the issue. The only problem is that this f value may not be a Date, it really can be any 6 characters according to the ACH specs.

What I believe we should do is make sure it's always 6 characters (which is what I thought strptime would do, my bad..) something like:

Suggested change
f.strftime('%y%m%d')
rescue
f
f = Date.parse(f) unless f.is_a? Date
f.strftime('%y%m%d')
rescue
f.rjust(6, " ")

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated the comment because we might want to do parse only if it's not a date.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand your goal but there are a few problems

  • f can be Time or DateTime
  • in case if f match to /^SD\d+$/ (e.g. SD12345)

Also, from the definition of the .field method, I see that it supports validation, maybe this is a more appropriate place for it?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The case for SDhhmm strings is handled on line 5

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The company_descriptive_date field of the batch header is optional and alphanumeric, it doesn't have to be parse-able, so I don't see how we could validate it as it really can be any 6 characters

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this covers all the cases:

Suggested change
f.strftime('%y%m%d')
rescue
f
f = Date.parse(f) unless f.respond_to?(:strftime)
f.strftime('%y%m%d')
rescue
f.to_s.rjust(6, ' ')
end

It will:

  • Try to parse the date only if f does not already respond to strftime
  • If it fails, pad the string with spaces up to 6 characters

What do you think @chubchenko?

@jm81 jm81 merged commit 75f6b38 into rubyritas:master Mar 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants