From 4a0e91f3ad97e43c851b0fba081c172f54d16c41 Mon Sep 17 00:00:00 2001 From: Shane Huston Date: Wed, 8 Jun 2022 12:33:41 +0100 Subject: [PATCH] Handle unspecified start date --- cmd/process.go | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/cmd/process.go b/cmd/process.go index 76bcf0e..c5f2cca 100644 --- a/cmd/process.go +++ b/cmd/process.go @@ -40,11 +40,7 @@ Formatted data output includes these supplied classifications by default. Any transactions which cannot be automatically classified based on the classifications.json file will be classified as "UNKNOWN" Foratted data can be used elsewhere to understand spending types and remaining budget per classification.`, Run: func(cmd *cobra.Command, args []string) { - startDate, err := time.Parse("20060102", start) - if err != nil { - log.Fatal("Could not parse start date: ", err) - } - startDate = startDate.Add(time.Hour * -24) + startDate := getStartDate(start) transactions.Process(revolutFile, aibFile, startDate) }, } @@ -56,3 +52,15 @@ func init() { processCmd.Flags().StringVarP(&aibFile, "aibFile", "a", "", "The path to the exported AIB statement file") processCmd.Flags().StringVarP(&start, "startDate", "s", "", "The earliest date to be processed (format yyyymmdd)") } + +func getStartDate(start string) time.Time { + if start != "" { + startDate, err := time.Parse("20060102", start) + if err != nil { + log.Fatal("Could not parse start date: ", err) + } + return startDate.Add(time.Hour * -24) + } + + return time.Unix(0, 0) +}