forked from moov-io/ach
-
Notifications
You must be signed in to change notification settings - Fork 0
/
converters.go
64 lines (53 loc) · 1.56 KB
/
converters.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// Copyright 2017 The ACH Authors
// Use of this source code is governed by an Apache License
// license that can be found in the LICENSE file.
package ach
import (
"strconv"
"strings"
"time"
)
// converters handles golang to ACH type Converters
type converters struct{}
func (c *converters) parseNumField(r string) (s int) {
s, _ = strconv.Atoi(strings.TrimSpace(r))
return s
}
// formatSimpleDate takes a time.Time and returns a string of YYMMDD
func (c *converters) formatSimpleDate(t time.Time) string {
return t.Format("060102")
}
// parseSimpleDate returns a time.Time when passed time as YYMMDD
func (c *converters) parseSimpleDate(s string) time.Time {
t, _ := time.Parse("060102", s)
return t
}
// formatSimpleTime returns a string of HHMM when passed a time.Time
func (c *converters) formatSimpleTime(t time.Time) string {
return t.Format("1504")
}
// parseSimpleTime returns a time.Time when passed a string of HHMM
func (c *converters) parseSimpleTime(s string) time.Time {
t, _ := time.Parse("1504", s)
return t
}
//func (v *Converters) numericField()
// alphaField Alphanumeric and Alphabetic fields are left-justified and space filled.
func (c *converters) alphaField(s string, max uint) string {
ln := uint(len(s))
if ln > max {
return s[:max]
}
s += strings.Repeat(" ", int(max-ln))
return s
}
// numericField right-justified, unisigned, and zero filled
func (c *converters) numericField(n int, max uint) string {
s := strconv.Itoa(n)
ln := uint(len(s))
if ln > max {
return s[ln-max:]
}
s = strings.Repeat("0", int(max-ln)) + s
return s
}