-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
ynabber.go
55 lines (43 loc) · 978 Bytes
/
ynabber.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
package ynabber
import (
"strconv"
"time"
)
type Ynabber struct {
Readers []Reader
Writers []Writer
}
type Reader interface {
Bulk() ([]Transaction, error)
}
type Writer interface {
Bulk([]Transaction) error
}
type Account struct {
ID ID
Name string
IBAN string
}
type ID string
type Payee string
type Milliunits int64
// Negate changes the sign of m to the opposite
func (m Milliunits) Negate() Milliunits {
return m * -1
}
type Transaction struct {
Account Account `json:"account"`
ID ID `json:"id"`
// Date is the date of the transaction in UTC time
Date time.Time `json:"date"`
Payee Payee `json:"payee"`
Memo string `json:"memo"`
Amount Milliunits `json:"amount"`
}
func (m Milliunits) String() string {
return strconv.FormatInt(int64(m), 10)
}
// MilliunitsFromAmount returns a transaction amount in YNABs milliunits format
func MilliunitsFromAmount(amount float64) Milliunits {
return Milliunits(amount * 1000)
}