~mendelmaleh/pfin

ref: 1f051309601a4da2841fade1e72cb120bccab370 pfin/pfin.go -rw-r--r-- 545 bytes
1f051309Mendel E Add license 3 months ago
                                                                                
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
package pfin

import (
	"strconv"
	"strings"
	"time"
)

const ISO8601 = "2006-01-02"

type Transaction interface {
	Date() time.Time
	Amount() float64
	Card() string
	Name() string

	// should be pfin.TxString
	String() string
}

func TxString(tx Transaction, sep string) string {
	var b strings.Builder

	b.WriteString(tx.Date().Format(ISO8601))
	b.WriteString(sep)

	b.WriteString(strconv.FormatFloat(tx.Amount(), 'f', 2, 64))
	b.WriteString(sep)

	b.WriteString(tx.Card())
	b.WriteString(sep)

	b.WriteString(tx.Name())

	return b.String()
}