mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-05-12 14:30:19 -05:00
fix last month search
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
Bugfix: Fix last month search
|
||||
|
||||
We've fixed the last month search edge case when currently is 31-th.
|
||||
|
||||
https://github.com/owncloud/ocis/issues/7629
|
||||
https://github.com/owncloud/ocis/pull/7742
|
||||
|
||||
The issue is related to the build-in package behavior https://github.com/golang/go/issues/31145
|
||||
@@ -115,7 +115,7 @@ func toTimeRange(in interface{}) (*time.Time, *time.Time, error) {
|
||||
from = n.BeginningOfMonth()
|
||||
to = n.EndOfMonth()
|
||||
case "last month":
|
||||
lastMonth := n.With(n.AddDate(0, -1, 0))
|
||||
lastMonth := n.With(n.BeginningOfMonth().AddDate(0, 0, -1))
|
||||
from = lastMonth.BeginningOfMonth()
|
||||
to = lastMonth.EndOfMonth()
|
||||
case "last 30 days":
|
||||
|
||||
@@ -694,6 +694,72 @@ func TestParse_DateTimeRestrictionNode(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "NaturalLanguage DateTimeNode - last month - edge case when last day of the month",
|
||||
patch: setWorldClock(t, "2023-10-31"),
|
||||
query: join([]string{
|
||||
`Mtime:"last month"`,
|
||||
}),
|
||||
ast: &ast.Ast{
|
||||
Nodes: []ast.Node{
|
||||
&ast.DateTimeNode{
|
||||
Key: "Mtime",
|
||||
Operator: &ast.OperatorNode{Value: ">="},
|
||||
Value: mustParseTime(t, "2023-09-01"),
|
||||
},
|
||||
&ast.OperatorNode{Value: kql.BoolAND},
|
||||
&ast.DateTimeNode{
|
||||
Key: "Mtime",
|
||||
Operator: &ast.OperatorNode{Value: "<="},
|
||||
Value: mustParseTime(t, "2023-09-30 23:59:59.999999999"),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "NaturalLanguage DateTimeNode - last month - edge case when last day of the month",
|
||||
patch: setWorldClock(t, "2023-03-31"),
|
||||
query: join([]string{
|
||||
`Mtime:"last month"`,
|
||||
}),
|
||||
ast: &ast.Ast{
|
||||
Nodes: []ast.Node{
|
||||
&ast.DateTimeNode{
|
||||
Key: "Mtime",
|
||||
Operator: &ast.OperatorNode{Value: ">="},
|
||||
Value: mustParseTime(t, "2023-02-01"),
|
||||
},
|
||||
&ast.OperatorNode{Value: kql.BoolAND},
|
||||
&ast.DateTimeNode{
|
||||
Key: "Mtime",
|
||||
Operator: &ast.OperatorNode{Value: "<="},
|
||||
Value: mustParseTime(t, "2023-02-28 23:59:59.999999999"),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "NaturalLanguage DateTimeNode - last month - edge case when last day of the month",
|
||||
patch: setWorldClock(t, "2024-03-31"),
|
||||
query: join([]string{
|
||||
`Mtime:"last month"`,
|
||||
}),
|
||||
ast: &ast.Ast{
|
||||
Nodes: []ast.Node{
|
||||
&ast.DateTimeNode{
|
||||
Key: "Mtime",
|
||||
Operator: &ast.OperatorNode{Value: ">="},
|
||||
Value: mustParseTime(t, "2024-02-01"),
|
||||
},
|
||||
&ast.OperatorNode{Value: kql.BoolAND},
|
||||
&ast.DateTimeNode{
|
||||
Key: "Mtime",
|
||||
Operator: &ast.OperatorNode{Value: "<="},
|
||||
Value: mustParseTime(t, "2024-02-29 23:59:59.999999999"),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "NaturalLanguage DateTimeNode - last month - the beginning of the year",
|
||||
patch: setWorldClock(t, "2023-01-01"),
|
||||
|
||||
Reference in New Issue
Block a user