Skip to content

Commit

Permalink
Keep settlement date when parsing files.
Browse files Browse the repository at this point in the history
  • Loading branch information
eweise committed Jul 19, 2021
1 parent 5ce71f8 commit 1998e0f
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 4 deletions.
5 changes: 3 additions & 2 deletions batchHeader.go
Expand Up @@ -179,8 +179,9 @@ func (bh *BatchHeader) Parse(record string) {
// 70-75 Date transactions are to be posted to the receivers' account.
// You almost always want the transaction to post as soon as possible, so put tomorrow's date in YYMMDD format
bh.EffectiveEntryDate = bh.validateSimpleDate(record[69:75])
// 76-79 Always blank (just fill with spaces)
bh.settlementDate = " "
// 76-78 Always blank if creating batches (just fill with spaces).
// Set to file value when parsing. Julian day format.
bh.settlementDate = bh.validateSettlementDate(record[75:78])
// 79-79 Always 1
bh.OriginatorStatusCode = bh.parseNumField(record[78:79])
// 80-87 Your ODFI's routing number without the last digit. The last digit is simply a
Expand Down
4 changes: 2 additions & 2 deletions iatBatchHeader.go
Expand Up @@ -235,8 +235,8 @@ func (iatBh *IATBatchHeader) Parse(record string) {
// 70-75 Date transactions are to be posted to the receivers' account.
// You almost always want the transaction to post as soon as possible, so put tomorrow's date in YYMMDD format
iatBh.EffectiveEntryDate = iatBh.validateSimpleDate(record[69:75])
// 76-79 Always blank (just fill with spaces)
iatBh.settlementDate = " "
// 76-78 Always blank (just fill with spaces)
iatBh.settlementDate = iatBh.validateSettlementDate(record[75:78])
// 79-79 Always 1
iatBh.OriginatorStatusCode = iatBh.parseNumField(record[78:79])
// 80-87 Your ODFI's routing number without the last digit. The last digit is simply a
Expand Down
25 changes: 25 additions & 0 deletions validators.go
Expand Up @@ -496,3 +496,28 @@ func CheckRoutingNumber(routingNumber string) error {
func (v *validator) roundUp10(n int) int {
return int(math.Ceil(float64(n)/10.0)) * 10
}

func (v *validator) validateSettlementDate(s string) string {
emptyField := " "

if s == emptyField {
return s
}

if len(s) != len(emptyField) {
return emptyField
}

day, err := strconv.Atoi(s)

if err != nil {
return emptyField
}

if day < 1 || day > 366 {
return emptyField
}

return s

}
24 changes: 24 additions & 0 deletions validators_test.go
Expand Up @@ -162,3 +162,27 @@ func TestValidators__isAlphanumeric(t *testing.T) {
})
}
}

func TestValidators__validateJulianDay(t *testing.T) {
empty := " "
cases := map[string]string{
// invalid
"": empty,
" ": empty,
"01": empty,
"01234": empty,
"XXX": empty,
"000": empty,
"367": empty,
// valid
"001": "001",
"020": "020",
"366": "366",
}
v := validator{}
for input, valid := range cases {
if v.validateSettlementDate(input) != valid {
t.Errorf("julian day=%s failed", input)
}
}
}

0 comments on commit 1998e0f

Please sign in to comment.