-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
feat: basic due date support #4835
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
package memopayload | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/usememos/memos/store" | ||
) | ||
|
||
func TestDueDateDetection(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
content string | ||
wantDueDate bool | ||
}{ | ||
{ | ||
name: "memo with due date", | ||
content: "This is a memo with due date @due(2025-01-15)", | ||
wantDueDate: true, | ||
}, | ||
{ | ||
name: "memo with due date at beginning", | ||
content: "@due(2025-12-31) This memo has a due date at the beginning", | ||
wantDueDate: true, | ||
}, | ||
{ | ||
name: "memo with due date in middle", | ||
content: "Meeting prep @due(2025-01-15) for the quarterly review", | ||
wantDueDate: true, | ||
}, | ||
{ | ||
name: "memo with task and due date", | ||
content: "- [ ] Complete project @due(2025-01-10)", | ||
wantDueDate: true, | ||
}, | ||
{ | ||
name: "memo with multiple due dates", | ||
content: "Task 1 @due(2025-01-10) and Task 2 @due(2025-01-15)", | ||
wantDueDate: true, | ||
}, | ||
{ | ||
name: "memo without due date", | ||
content: "This is a regular memo without any due date", | ||
wantDueDate: false, | ||
}, | ||
{ | ||
name: "memo with malformed due date", | ||
content: "This has a malformed @due(not-a-date) pattern", | ||
wantDueDate: false, | ||
}, | ||
{ | ||
name: "memo with partial due date pattern", | ||
content: "This mentions @due but not complete pattern", | ||
wantDueDate: false, | ||
}, | ||
{ | ||
name: "memo with due date in code block", | ||
content: "```\n@due(2025-01-15)\n```", | ||
wantDueDate: true, // Should still detect even in code blocks | ||
}, | ||
{ | ||
name: "empty memo", | ||
content: "", | ||
wantDueDate: false, | ||
}, | ||
{ | ||
name: "memo with invalid date format", | ||
content: "Invalid date @due(25-01-15)", | ||
wantDueDate: false, | ||
}, | ||
{ | ||
name: "memo with valid date formats", | ||
content: "Valid dates @due(2025-01-15) and @due(2025-12-31)", | ||
wantDueDate: true, | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
memo := &store.Memo{ | ||
Content: tt.content, | ||
} | ||
|
||
err := RebuildMemoPayload(memo) | ||
require.NoError(t, err) | ||
require.NotNil(t, memo.Payload) | ||
require.NotNil(t, memo.Payload.Property) | ||
|
||
require.Equal(t, tt.wantDueDate, memo.Payload.Property.HasDueDate, | ||
"Expected HasDueDate to be %v for content: %s", tt.wantDueDate, tt.content) | ||
}) | ||
} | ||
} | ||
|
||
func TestDueDateDetectionWithOtherProperties(t *testing.T) { | ||
memo := &store.Memo{ | ||
Content: "Check out https://example.com and complete task @due(2025-01-15)\n\n- [ ] incomplete task", | ||
} | ||
|
||
err := RebuildMemoPayload(memo) | ||
require.NoError(t, err) | ||
require.NotNil(t, memo.Payload) | ||
require.NotNil(t, memo.Payload.Property) | ||
|
||
// Should detect due date along with other properties | ||
require.True(t, memo.Payload.Property.HasDueDate) | ||
require.True(t, memo.Payload.Property.HasLink) | ||
require.True(t, memo.Payload.Property.HasTaskList) | ||
require.True(t, memo.Payload.Property.HasIncompleteTasks) | ||
} |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -111,6 +111,9 @@ func (d *DB) ListMemos(ctx context.Context, find *store.FindMemo) ([]*store.Memo | |||||
if v.HasIncompleteTasks { | ||||||
where = append(where, "JSON_EXTRACT(`memo`.`payload`, '$.property.hasIncompleteTasks') IS TRUE") | ||||||
} | ||||||
if v.HasDueDate { | ||||||
where = append(where, "JSON_EXTRACT(`memo`.`payload`, '$.property.hasDueDate') IS TRUE") | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. MySQL JSON path must reference
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||
} | ||||||
} | ||||||
if v := find.Filter; v != nil { | ||||||
// Parse filter string and return the parsed expression. | ||||||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -102,6 +102,9 @@ func (d *DB) ListMemos(ctx context.Context, find *store.FindMemo) ([]*store.Memo | |||||
if v.HasIncompleteTasks { | ||||||
where = append(where, "(memo.payload->'property'->>'hasIncompleteTasks')::BOOLEAN IS TRUE") | ||||||
} | ||||||
if v.HasDueDate { | ||||||
where = append(where, "(memo.payload->'property'->>'hasDueDate')::BOOLEAN IS TRUE") | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Postgres JSON operator should use
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||
} | ||||||
} | ||||||
if v := find.Filter; v != nil { | ||||||
// Parse filter string and return the parsed expression. | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Compiling the regex on every invocation can be expensive. Move
MustCompile
to a package-levelvar
so it’s compiled once.Copilot uses AI. Check for mistakes.