diff --git a/main.go b/main.go index 66e2bd8..3e013f5 100644 --- a/main.go +++ b/main.go @@ -18,6 +18,10 @@ import ( "gopkg.in/yaml.v3" ) +const ( + maxWidth = 100 +) + type timeSlice []time.Time func (s timeSlice) Len() int { return len(s) } @@ -330,10 +334,9 @@ func (tl *TransactionLog) deleteDay(date time.Time) { } func calculateShift(transactionLog TransactionLog, transaction Transaction) time.Time { - if transaction.Amount > 0 { + if isWeekend(transaction.Date) { add := 1 newDate := transaction.Date - if transaction.Shift == "early" { add = -1 } @@ -343,7 +346,6 @@ func calculateShift(transactionLog TransactionLog, transaction Transaction) time } return newDate - } if transaction.Shift == "early" { @@ -426,15 +428,15 @@ func currentDay() time.Time { } func firstOfMonth(t time.Time) time.Time { - return time.Date(t.Year(), t.Month(), 1, 0, 0, 0, 0, time.Now().Location()) + return time.Date(t.Year(), t.Month(), 1, 0, 0, 0, 0, t.Location()) } func lastOfMonth(t time.Time) time.Time { - return time.Date(t.Year(), t.Month()+1, 0, 0, 0, 0, 0, time.Now().Location()) + return time.Date(t.Year(), t.Month()+1, 0, 0, 0, 0, 0, t.Location()) } func stripTime(t time.Time) time.Time { - return time.Date(t.Year(), t.Month(), t.Day(), 0, 0, 0, 0, time.Now().Location()) + return time.Date(t.Year(), t.Month(), t.Day(), 0, 0, 0, 0, t.Location()) } func calculateFrequency(frequency string, startDate time.Time, endDate time.Time, hardDate bool) []time.Time { @@ -604,8 +606,8 @@ func printOutput(logDay LogDay) { fullWidth := getTerminalWidth() - if fullWidth > 120 { - fullWidth = 120 + if fullWidth > maxWidth { + fullWidth = maxWidth } border := strings.Repeat("=", fullWidth) @@ -619,26 +621,25 @@ func printOutput(logDay LogDay) { } for _, charge := range logDay.transactions() { prefix := "-" + suffix := "|" if charge.Amount > 0 { prefix = "+" } if charge.Delayed { - suffix := fmt.Sprintf("(%s - %s) |", "Late", charge.OriginDate.Format("Jan 02 2006")) - printTransactionLine(charge.Amount, charge.Name, prefix, suffix, fullWidth) + suffix = fmt.Sprintf("(%s - %s) |", "Late", charge.OriginDate.Format("Jan 02 2006")) } else if charge.Date != charge.OriginDate { - suffix := fmt.Sprintf("(%s - %s) |", "Weekend", charge.OriginDate.Format("Jan 02 2006")) - printTransactionLine(charge.Amount, charge.Name, prefix, suffix, fullWidth) - } else { - printTransactionLine(charge.Amount, charge.Name, prefix, "|", fullWidth) + suffix = fmt.Sprintf("(%s - %s) |", "Weekend", charge.OriginDate.Format("Jan 02 2006")) } + + printTransactionLine(charge.Amount, charge.Name, prefix, suffix, fullWidth) } fmt.Println(divider) for _, v := range logDay.EndingBalance { printTransactionLine(v.Balance, v.Name, "", "|", fullWidth) } - fmt.Println(border + "\n") + fmt.Printf("%s\n\n", border) } func main() {