fix last month search

This commit is contained in:
Roman Perekhod
2023-11-16 16:24:43 +01:00
parent a9afb49bed
commit 8a6464798f
3 changed files with 75 additions and 1 deletions
@@ -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
+1 -1
View File
@@ -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"),