dates can be strings i dont care
parent
459bc54760
commit
392036f2b0
|
|
@ -1,9 +1,5 @@
|
|||
package ledger
|
||||
|
||||
import (
|
||||
"time"
|
||||
)
|
||||
|
||||
type Currency string
|
||||
|
||||
const (
|
||||
|
|
@ -11,14 +7,14 @@ const (
|
|||
)
|
||||
|
||||
type Delta struct {
|
||||
Date time.Time
|
||||
Date string
|
||||
Account string
|
||||
Value float64
|
||||
Currency Currency
|
||||
Description string
|
||||
}
|
||||
|
||||
func newDelta(d time.Time, desc, acc string, v float64, c string) Delta {
|
||||
func newDelta(d, desc, acc string, v float64, c string) Delta {
|
||||
return Delta{
|
||||
Date: d,
|
||||
Account: acc,
|
||||
|
|
|
|||
|
|
@ -2,14 +2,10 @@ package ledger
|
|||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestDelta(t *testing.T) {
|
||||
d, err := time.Parse("2006-01-02", "2099-08-07")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
d := "2099-08-07"
|
||||
delta := newDelta(d, "", "name", 34.56, "$")
|
||||
|
||||
if delta.Date != d {
|
||||
|
|
@ -26,7 +22,7 @@ func TestDelta(t *testing.T) {
|
|||
}
|
||||
t.Log(delta)
|
||||
|
||||
d2, _ := time.Parse("2006-01-02", "2099-09-08")
|
||||
d2 := "2099-09-08"
|
||||
delta2 := newDelta(d2, "", "name", 11.11, "$")
|
||||
|
||||
combined := delta.Plus(delta2)
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@ import (
|
|||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"time"
|
||||
)
|
||||
|
||||
type File string
|
||||
|
|
@ -60,7 +59,7 @@ func (file File) Deltas(like ...Like) ([]Delta, error) {
|
|||
}
|
||||
|
||||
type transaction struct {
|
||||
date time.Time
|
||||
date string
|
||||
description string
|
||||
payee string
|
||||
recipients []transactionRecipient
|
||||
|
|
@ -89,7 +88,7 @@ func (file File) transactions() ([]transaction, error) {
|
|||
if !one.empty() {
|
||||
result = append(result, one)
|
||||
}
|
||||
if errors.Is(err, io.EOF) {
|
||||
if err == io.EOF {
|
||||
return result, nil
|
||||
}
|
||||
if err != nil {
|
||||
|
|
@ -99,5 +98,36 @@ func (file File) transactions() ([]transaction, error) {
|
|||
}
|
||||
|
||||
func readTransaction(r io.Reader) (transaction, error) {
|
||||
return transaction{}, io.EOF
|
||||
result := transaction{}
|
||||
var err error
|
||||
|
||||
if result.date, err = readTransactionDate(r); err != nil {
|
||||
return result, fmt.Errorf("did not find transaction date: %w", err)
|
||||
}
|
||||
|
||||
if result.description, err = readTransactionDescription(r); err != nil {
|
||||
return result, fmt.Errorf("did not find transaction description: %w", err)
|
||||
}
|
||||
|
||||
return transaction{}, errors.New("not impl: reading payee, recipients")
|
||||
}
|
||||
|
||||
func readTransactionDate(r io.Reader) (string, error) {
|
||||
var firstByte [1]byte
|
||||
for firstByte[0] < '0' || firstByte[0] > '9' {
|
||||
if _, err := r.Read(firstByte[:]); err != nil {
|
||||
return "", err
|
||||
}
|
||||
}
|
||||
|
||||
restOfDate := make([]byte, len("2006-01-02")-1)
|
||||
if _, err := r.Read(restOfDate); err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return fmt.Sprintf("%s%s", firstByte, restOfDate), nil
|
||||
}
|
||||
|
||||
func readTransactionDescription(r io.Reader) (string, error) {
|
||||
return "", io.EOF
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,35 +5,30 @@ import (
|
|||
"io"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestFileDeltas(t *testing.T) {
|
||||
d := func(s string) time.Time {
|
||||
v, _ := time.Parse("2006-01-02", s)
|
||||
return v
|
||||
}
|
||||
happy := []Delta{
|
||||
{
|
||||
Date: d("2022-12-12"),
|
||||
Date: "2022-12-12",
|
||||
Account: "AssetAccount:Cash:Fidelity76",
|
||||
Value: -97.92,
|
||||
Currency: USD,
|
||||
},
|
||||
{
|
||||
Date: d("2022-12-12"),
|
||||
Date: "2022-12-12",
|
||||
Account: "Withdrawal:0:SharedHome:DominionEnergy",
|
||||
Value: 97.92,
|
||||
Currency: USD,
|
||||
},
|
||||
{
|
||||
Date: d("2022-12-12"),
|
||||
Date: "2022-12-12",
|
||||
Account: "AssetAccount:Cash:Fidelity76",
|
||||
Value: -1.00,
|
||||
Currency: USD,
|
||||
},
|
||||
{
|
||||
Date: d("2022-12-12"),
|
||||
Date: "2022-12-12",
|
||||
Account: "Debts:Credit:ChaseFreedomUltdVisa",
|
||||
Value: 1.00,
|
||||
Currency: USD,
|
||||
|
|
@ -75,10 +70,6 @@ func TestFileDeltas(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestReadTransaction(t *testing.T) {
|
||||
d := func(s string) time.Time {
|
||||
v, _ := time.Parse("2006-01-02", s)
|
||||
return v
|
||||
}
|
||||
cases := map[string]struct {
|
||||
input string
|
||||
want transaction
|
||||
|
|
@ -101,7 +92,7 @@ func TestReadTransaction(t *testing.T) {
|
|||
C:D $-1.00
|
||||
`,
|
||||
want: transaction{
|
||||
date: d("2003-04-05"),
|
||||
date: "2003-04-05",
|
||||
description: "Reasoning here",
|
||||
payee: "",
|
||||
recipients: []transactionRecipient{
|
||||
|
|
|
|||
Loading…
Reference in New Issue