Handle $ and , in amount
This commit is contained in:
22
main.go
22
main.go
@@ -83,12 +83,12 @@ type Transaction struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type TransactionYaml struct {
|
type TransactionYaml struct {
|
||||||
Name string `yaml:"name"`
|
Name string `yaml:"name"`
|
||||||
Amount float64 `yaml:"amount"`
|
Amount string `yaml:"amount"`
|
||||||
Date string `yaml:"date"`
|
Date string `yaml:"date"`
|
||||||
Delayable string `yaml:"delayable"`
|
Delayable string `yaml:"delayable"`
|
||||||
Frequency string `yaml:"frequency,omitempty"`
|
Frequency string `yaml:"frequency,omitempty"`
|
||||||
Shift string `yaml:"shift"`
|
Shift string `yaml:"shift"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type TransactionLog struct {
|
type TransactionLog struct {
|
||||||
@@ -204,8 +204,16 @@ func parseTransaction(transactionYaml TransactionYaml) (*Transaction, error) {
|
|||||||
return nil, err
|
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{
|
transaction := &Transaction{
|
||||||
Amount: transactionYaml.Amount,
|
Amount: amount,
|
||||||
Date: stripTime(date),
|
Date: stripTime(date),
|
||||||
Delayable: delayable,
|
Delayable: delayable,
|
||||||
Frequency: transactionYaml.Frequency,
|
Frequency: transactionYaml.Frequency,
|
||||||
|
|||||||
Reference in New Issue
Block a user