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:
4 files changed
+35
-48
No files matched your search
+16
-16
@@ -1407,7 +1407,7 @@ func TestQueryInvoices(t *testing.T) {
|
||||
{
|
||||
query: invpkg.InvoiceQuery{
|
||||
NumMaxInvoices: numInvoices,
|
||||
CreationDateEnd: time.Unix(25, 0),
|
||||
CreationDateEnd: 25,
|
||||
},
|
||||
expected: invoices[:25],
|
||||
},
|
||||
@@ -1415,7 +1415,7 @@ func TestQueryInvoices(t *testing.T) {
|
||||
{
|
||||
query: invpkg.InvoiceQuery{
|
||||
NumMaxInvoices: numInvoices,
|
||||
CreationDateStart: time.Unix(26, 0),
|
||||
CreationDateStart: 26,
|
||||
},
|
||||
expected: invoices[25:],
|
||||
},
|
||||
@@ -1424,7 +1424,7 @@ func TestQueryInvoices(t *testing.T) {
|
||||
query: invpkg.InvoiceQuery{
|
||||
PendingOnly: true,
|
||||
NumMaxInvoices: numInvoices,
|
||||
CreationDateEnd: time.Unix(25, 0),
|
||||
CreationDateEnd: 25,
|
||||
},
|
||||
expected: pendingInvoices[:13],
|
||||
},
|
||||
@@ -1433,7 +1433,7 @@ func TestQueryInvoices(t *testing.T) {
|
||||
query: invpkg.InvoiceQuery{
|
||||
PendingOnly: true,
|
||||
NumMaxInvoices: numInvoices,
|
||||
CreationDateStart: time.Unix(26, 0),
|
||||
CreationDateStart: 26,
|
||||
},
|
||||
expected: pendingInvoices[13:],
|
||||
},
|
||||
@@ -1442,7 +1442,7 @@ func TestQueryInvoices(t *testing.T) {
|
||||
query: invpkg.InvoiceQuery{
|
||||
IndexOffset: 20,
|
||||
NumMaxInvoices: numInvoices,
|
||||
CreationDateEnd: time.Unix(30, 0),
|
||||
CreationDateEnd: 30,
|
||||
},
|
||||
// Since we're skipping to invoice 20 and iterating
|
||||
// to invoice 30, we'll expect those invoices.
|
||||
@@ -1455,7 +1455,7 @@ func TestQueryInvoices(t *testing.T) {
|
||||
IndexOffset: 21,
|
||||
Reversed: true,
|
||||
NumMaxInvoices: numInvoices,
|
||||
CreationDateStart: time.Unix(11, 0),
|
||||
CreationDateStart: 11,
|
||||
},
|
||||
// Since we're skipping to invoice 20 and iterating
|
||||
// backward to invoice 10, we'll expect those invoices.
|
||||
@@ -1465,8 +1465,8 @@ func TestQueryInvoices(t *testing.T) {
|
||||
{
|
||||
query: invpkg.InvoiceQuery{
|
||||
NumMaxInvoices: numInvoices,
|
||||
CreationDateStart: time.Unix(11, 0),
|
||||
CreationDateEnd: time.Unix(20, 0),
|
||||
CreationDateStart: 11,
|
||||
CreationDateEnd: 20,
|
||||
},
|
||||
expected: invoices[10:20],
|
||||
},
|
||||
@@ -1475,8 +1475,8 @@ func TestQueryInvoices(t *testing.T) {
|
||||
query: invpkg.InvoiceQuery{
|
||||
PendingOnly: true,
|
||||
NumMaxInvoices: numInvoices,
|
||||
CreationDateStart: time.Unix(11, 0),
|
||||
CreationDateEnd: time.Unix(20, 0),
|
||||
CreationDateStart: 11,
|
||||
CreationDateEnd: 20,
|
||||
},
|
||||
expected: pendingInvoices[5:10],
|
||||
},
|
||||
@@ -1486,8 +1486,8 @@ func TestQueryInvoices(t *testing.T) {
|
||||
query: invpkg.InvoiceQuery{
|
||||
Reversed: true,
|
||||
NumMaxInvoices: numInvoices,
|
||||
CreationDateStart: time.Unix(11, 0),
|
||||
CreationDateEnd: time.Unix(20, 0),
|
||||
CreationDateStart: 11,
|
||||
CreationDateEnd: 20,
|
||||
},
|
||||
expected: invoices[10:20],
|
||||
},
|
||||
@@ -1498,8 +1498,8 @@ func TestQueryInvoices(t *testing.T) {
|
||||
PendingOnly: true,
|
||||
Reversed: true,
|
||||
NumMaxInvoices: numInvoices,
|
||||
CreationDateStart: time.Unix(11, 0),
|
||||
CreationDateEnd: time.Unix(20, 0),
|
||||
CreationDateStart: 11,
|
||||
CreationDateEnd: 20,
|
||||
},
|
||||
expected: pendingInvoices[5:10],
|
||||
},
|
||||
@@ -1508,8 +1508,8 @@ func TestQueryInvoices(t *testing.T) {
|
||||
{
|
||||
query: invpkg.InvoiceQuery{
|
||||
NumMaxInvoices: numInvoices,
|
||||
CreationDateStart: time.Unix(20, 0),
|
||||
CreationDateEnd: time.Unix(11, 0),
|
||||
CreationDateStart: 20,
|
||||
CreationDateEnd: 11,
|
||||
},
|
||||
expected: nil,
|
||||
},
|
||||
|
||||
+8
-12
@@ -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
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user