multi: fix timestamp filters for invoice query

This commit fixes the timestamp precision to always compare the dates
using unix seconds for invoices.
This commit is contained in:
yyforyongyu
2024-01-26 11:11:37 +08:00
parent 221e7ff898
commit 18333e8c7d
4 changed files with 35 additions and 48 deletions

View File

@@ -497,11 +497,7 @@ func (d *DB) FetchPendingInvoices(_ context.Context) (
func (d *DB) QueryInvoices(_ context.Context, q invpkg.InvoiceQuery) (
invpkg.InvoiceSlice, error) {
var (
resp invpkg.InvoiceSlice
startDateSet = !q.CreationDateStart.IsZero()
endDateSet = !q.CreationDateEnd.IsZero()
)
var resp invpkg.InvoiceSlice
err := kvdb.View(d, func(tx kvdb.RTx) error {
// If the bucket wasn't found, then there aren't any invoices
@@ -541,20 +537,20 @@ func (d *DB) QueryInvoices(_ context.Context, q invpkg.InvoiceQuery) (
return false, nil
}
// Get the creation time in Unix seconds, this always
// rounds down the nanoseconds to full seconds.
createTime := invoice.CreationDate.Unix()
// Skip any invoices that were created before the
// specified time.
if startDateSet && invoice.CreationDate.Before(
q.CreationDateStart,
) {
if createTime < q.CreationDateStart {
return false, nil
}
// Skip any invoices that were created after the
// specified time.
if endDateSet && invoice.CreationDate.After(
q.CreationDateEnd,
) {
if q.CreationDateEnd != 0 &&
createTime > q.CreationDateEnd {
return false, nil
}