forked from howeyc/ledger
-
Notifications
You must be signed in to change notification settings - Fork 1
/
types.go
44 lines (33 loc) · 1.19 KB
/
types.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
package ledger
import (
"math/big"
"time"
)
// Account holds the name and balance
type Account struct {
Name string
Balance *big.Rat
}
type sortAccounts []*Account
func (s sortAccounts) Len() int { return len(s) }
func (s sortAccounts) Swap(i, j int) { s[i], s[j] = s[j], s[i] }
type sortAccountsByName struct{ sortAccounts }
func (s sortAccountsByName) Less(i, j int) bool {
return s.sortAccounts[i].Name < s.sortAccounts[j].Name
}
// Transaction is the basis of a ledger. The ledger holds a list of transactions.
// A Transaction has a Payee, Date (with no time, or to put another way, with
// hours,minutes,seconds values that probably doesn't make sense), and a list of
// Account values that hold the value of the transaction for each account.
type Transaction struct {
Payee string
Date time.Time
AccountChanges []Account
}
type sortTransactions []*Transaction
func (s sortTransactions) Len() int { return len(s) }
func (s sortTransactions) Swap(i, j int) { s[i], s[j] = s[j], s[i] }
type sortTransactionsByDate struct{ sortTransactions }
func (s sortTransactionsByDate) Less(i, j int) bool {
return s.sortTransactions[i].Date.Before(s.sortTransactions[j].Date)
}