From fc228d329e78f5ed1dd317df83af6d9b9e6f1b84 Mon Sep 17 00:00:00 2001 From: Samuel Attwood Date: Tue, 17 Dec 2024 21:07:23 -0500 Subject: [PATCH] Handle $ and , in amount --- main.go | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/main.go b/main.go index b4bd422..db10cb6 100644 --- a/main.go +++ b/main.go @@ -83,12 +83,12 @@ type Transaction struct { } type TransactionYaml struct { - Name string `yaml:"name"` - Amount float64 `yaml:"amount"` - Date string `yaml:"date"` - Delayable string `yaml:"delayable"` - Frequency string `yaml:"frequency,omitempty"` - Shift string `yaml:"shift"` + Name string `yaml:"name"` + Amount string `yaml:"amount"` + Date string `yaml:"date"` + Delayable string `yaml:"delayable"` + Frequency string `yaml:"frequency,omitempty"` + Shift string `yaml:"shift"` } type TransactionLog struct { @@ -204,8 +204,16 @@ func parseTransaction(transactionYaml TransactionYaml) (*Transaction, error) { return nil, err } + amountStr := strings.ReplaceAll(transactionYaml.Amount, "$", "") + amountStr = strings.ReplaceAll(amountStr, ",", "") + + amount, err := strconv.ParseFloat(amountStr, 32) + if err != nil { + return nil, err + } + transaction := &Transaction{ - Amount: transactionYaml.Amount, + Amount: amount, Date: stripTime(date), Delayable: delayable, Frequency: transactionYaml.Frequency,