~whereswaldon/ledger

1ae357a9a52ed815863233db8bd15f4488db9c3f — Chris Howey 1 year, 9 months ago 3445679
fix: have start/end dates be inclusive for command

Fixes #34
M date.go => date.go +3 -0
@@ 129,6 129,9 @@ func startEndTime(trans []*Transaction) (start, end time.Time) {
		}
	}

	// to include last days' transactions in date period splits
	end = end.Add(time.Second)

	return
}


M ledger/cmd/print.go => ledger/cmd/print.go +4 -14
@@ 39,6 39,9 @@ func cliTransactions() ([]*ledger.Transaction, error) {
		return nil, errors.New("unable to parse start or end date string argument")
	}

	// include end dates' transactions too
	parsedEndDate = parsedEndDate.Add(time.Second)

	var generalLedger []*ledger.Transaction
	var parseError error
	if ledgerFilePath == "-" {


@@ 54,20 57,7 @@ func cliTransactions() ([]*ledger.Transaction, error) {
		return generalLedger[i].Date.Before(generalLedger[j].Date)
	})

	timeStartIndex, timeEndIndex := 0, 0
	for idx := 0; idx < len(generalLedger); idx++ {
		if generalLedger[idx].Date.After(parsedStartDate) {
			timeStartIndex = idx
			break
		}
	}
	for idx := len(generalLedger) - 1; idx >= 0; idx-- {
		if generalLedger[idx].Date.Before(parsedEndDate) {
			timeEndIndex = idx
			break
		}
	}
	generalLedger = generalLedger[timeStartIndex : timeEndIndex+1]
	generalLedger = ledger.TransactionsInDateRange(generalLedger, parsedStartDate, parsedEndDate)

	origLedger := generalLedger
	generalLedger = make([]*ledger.Transaction, 0)

M ledger/cmd/printAccounts.go => ledger/cmd/printAccounts.go +1 -1
@@ 60,7 60,7 @@ func init() {

	var startDate, endDate time.Time
	startDate = time.Date(1970, 1, 1, 0, 0, 0, 0, time.Local)
	endDate = time.Now().Add(time.Hour * 24)
	endDate = time.Now()
	accountsCmd.Flags().StringVarP(&startString, "begin-date", "b", startDate.Format(transactionDateFormat), "Begin date of transaction processing.")
	accountsCmd.Flags().StringVarP(&endString, "end-date", "e", endDate.Format(transactionDateFormat), "End date of transaction processing.")
	accountsCmd.Flags().BoolVarP(&accountLeavesOnly, "leaves-only", "l", false, "Only show most-depth accounts")

M ledger/cmd/printBalance.go => ledger/cmd/printBalance.go +1 -1
@@ 43,7 43,7 @@ func init() {

	var startDate, endDate time.Time
	startDate = time.Date(1970, 1, 1, 0, 0, 0, 0, time.Local)
	endDate = time.Now().Add(time.Hour * 24)
	endDate = time.Now()
	balanceCmd.Flags().StringVarP(&startString, "begin-date", "b", startDate.Format(transactionDateFormat), "Begin date of transaction processing.")
	balanceCmd.Flags().StringVarP(&endString, "end-date", "e", endDate.Format(transactionDateFormat), "End date of transaction processing.")
	balanceCmd.Flags().StringVar(&payeeFilter, "payee", "", "Filter output to payees that contain this string.")

M ledger/cmd/printEquity.go => ledger/cmd/printEquity.go +1 -1
@@ 60,7 60,7 @@ func init() {

	var startDate, endDate time.Time
	startDate = time.Date(1970, 1, 1, 0, 0, 0, 0, time.Local)
	endDate = time.Now().Add(time.Hour * 24)
	endDate = time.Now()
	equityCmd.Flags().StringVarP(&startString, "begin-date", "b", startDate.Format(transactionDateFormat), "Begin date of transaction processing.")
	equityCmd.Flags().StringVarP(&endString, "end-date", "e", endDate.Format(transactionDateFormat), "End date of transaction processing.")
}