Skip to content

Commit af8f85a

Browse files
committed
Filter using tempDueDate
1 parent 038c8da commit af8f85a

File tree

6 files changed

+26
-15
lines changed

6 files changed

+26
-15
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ repo_name := $(notdir ${repo_path})
55

66
.PHONY: gobuild
77
gobuild:
8-
go build -v ./...
8+
go build -v -x -o bin/ ./...
99

1010
.PHONY: run
1111
run:

internal/model/note.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,11 @@ type Note struct {
2525
// Status can be "pending", "done", or "suspended".
2626
// The "pending" status is special, and notes marked with it show up everywhere, whereas
2727
// the nodes marked with other status show up only under "Search" or their dedicated menu.
28-
Status NoteStatus `json:"status"`
29-
TagIds []int `json:"tag_ids"`
30-
IsMain bool `json:"is_main"`
31-
CompleteBy int64 `json:"complete_by"`
28+
Status NoteStatus `json:"status"`
29+
TagIds []int `json:"tag_ids"`
30+
IsMain bool `json:"is_main"`
31+
CompleteBy int64 `json:"complete_by"`
32+
tempDueDate int64
3233
BaseStruct
3334
}
3435

internal/model/notes.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,13 @@ func (notes Notes) ExternalTexts(maxStrLen int, repeatAnnuallyTagId int, repeatM
4141
return allTexts
4242
}
4343

44+
// PopulateTempDueDate popultes tempDueDate field of note from its CompleteBy field.
45+
func (notes Notes) PopulateTempDueDate() {
46+
for _, note := range notes {
47+
note.tempDueDate = note.CompleteBy
48+
}
49+
}
50+
4451
// WithStatus filters-in notes with given status (such as "pending" status).
4552
// It returns empty Notes if no matching Note is found (even when given status doesn't exist).
4653
func (notes Notes) WithStatus(status NoteStatus) Notes {

internal/model/notes_by_due_date.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ type NotesByDueDate []*Note
99

1010
func (c NotesByDueDate) Len() int { return len(c) }
1111
func (c NotesByDueDate) Swap(i, j int) { c[i], c[j] = c[j], c[i] }
12-
func (c NotesByDueDate) Less(i, j int) bool { return c[i].CompleteBy < c[j].CompleteBy }
12+
func (c NotesByDueDate) Less(i, j int) bool { return c[i].tempDueDate < c[j].tempDueDate }

internal/model/notes_by_due_date_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ func TestNotesByDueDate(t *testing.T) {
1414
notes = append(notes, &model.Note{Text: "2", Status: model.NoteStatus_Pending, BaseStruct: model.BaseStruct{UpdatedAt: 1600000004}, CompleteBy: 1800000004})
1515
notes = append(notes, &model.Note{Text: "3", Status: model.NoteStatus_Done, BaseStruct: model.BaseStruct{UpdatedAt: 1600000003}, CompleteBy: 1800000002})
1616
notes = append(notes, &model.Note{Text: "4", Status: model.NoteStatus_Done, BaseStruct: model.BaseStruct{UpdatedAt: 1600000002}, CompleteBy: 1800000001})
17+
model.Notes(notes).PopulateTempDueDate()
1718
sort.Sort(model.NotesByDueDate(notes))
1819
var gotTexts []string
1920
for _, value := range notes {

internal/model/reminder_data.go

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -428,32 +428,34 @@ func (rd *ReminderData) NotesApprachingDueDate(view string) Notes {
428428
// assuming there are at least 100 notes (on average)
429429
currentNotes := make([]*Note, 0, 100)
430430
repeatTagIDs := rd.TagIdsForGroup("repeat")
431+
// populate tempDueDate
432+
pendingNotes.PopulateTempDueDate()
431433
// populating currentNotes
432434
for _, note := range pendingNotes {
433435
noteIDsWithRepeat := utils.GetCommonMembersOfSlices(note.TagIds, repeatTagIDs)
434436
// first process notes WITHOUT tag with group "repeat"
435437
// start showing such notes 7 days in advance from their due date, and until they are marked done
436-
minDay := note.CompleteBy - 7*24*60*60
438+
minDay := note.tempDueDate - 7*24*60*60
437439
if view == "long" {
438-
minDay = note.CompleteBy - 365*24*60*60
440+
minDay = note.tempDueDate - 365*24*60*60
439441
}
440442
currentTimestamp := utils.CurrentUnixTimestamp()
441-
if (len(noteIDsWithRepeat) == 0) && (note.CompleteBy != 0) && (currentTimestamp >= minDay) {
443+
if (len(noteIDsWithRepeat) == 0) && (note.tempDueDate != 0) && (currentTimestamp >= minDay) {
442444
currentNotes = append(currentNotes, note)
443445
}
444446
// check notes with tag with group "repeat"
445447
// start showing notes with "repeat-annually" 7 days in advance
446448
// start showing notes with "repeat-monthly" 3 days in advance
447449
// don't show such notes after their due date is past by 2 day
448-
if (len(noteIDsWithRepeat) > 0) && (note.CompleteBy != 0) {
450+
if (len(noteIDsWithRepeat) > 0) && (note.tempDueDate != 0) {
449451
// check for repeat-annually tag
450-
// note: for the CompleteBy date of the note, we accept only date
452+
// note: for the tempDueDate date of the note, we accept only date
451453
// so, even if there is a time element recorded the the timestamp,
452454
// we ignore it
453455
repeatAnnuallyTag := rd.TagFromSlug("repeat-annually")
454456
repeatMonthlyTag := rd.TagFromSlug("repeat-monthly")
455457
if (repeatAnnuallyTag != nil) && utils.IsMemberOfSlice(repeatAnnuallyTag.Id, note.TagIds) {
456-
_, noteMonth, noteDay := utils.UnixTimestampToTime(note.CompleteBy).Date()
458+
_, noteMonth, noteDay := utils.UnixTimestampToTime(note.tempDueDate).Date()
457459
noteTimestampCurrent := utils.UnixTimestampForCorrespondingCurrentYear(int(noteMonth), noteDay)
458460
noteTimestampPrevious := noteTimestampCurrent - 365*24*60*60
459461
noteTimestampNext := noteTimestampCurrent + 365*24*60*60
@@ -464,14 +466,14 @@ func (rd *ReminderData) NotesApprachingDueDate(view string) Notes {
464466
}
465467
shouldDisplay, matchingTimestamp := utils.MatchedTimestamp(noteTimestampCurrent, noteTimestampPrevious, noteTimestampNext, daysBefore, daysAfter)
466468
// temporarity update note's timestamp
467-
note.CompleteBy = matchingTimestamp
469+
note.tempDueDate = matchingTimestamp
468470
if shouldDisplay {
469471
currentNotes = append(currentNotes, note)
470472
}
471473
}
472474
// check for repeat-monthly tag
473475
if (repeatMonthlyTag != nil) && utils.IsMemberOfSlice(repeatMonthlyTag.Id, note.TagIds) {
474-
_, _, noteDay := utils.UnixTimestampToTime(note.CompleteBy).Date()
476+
_, _, noteDay := utils.UnixTimestampToTime(note.tempDueDate).Date()
475477
noteTimestampCurrent := utils.UnixTimestampForCorrespondingCurrentYearMonth(noteDay)
476478
noteTimestampPrevious := noteTimestampCurrent - 30*24*60*60
477479
noteTimestampNext := noteTimestampCurrent + 30*24*60*60
@@ -482,7 +484,7 @@ func (rd *ReminderData) NotesApprachingDueDate(view string) Notes {
482484
}
483485
shouldDisplay, matchingTimestamp := utils.MatchedTimestamp(noteTimestampCurrent, noteTimestampPrevious, noteTimestampNext, daysBefore, daysAfter)
484486
// temporarity update note's timestamp
485-
note.CompleteBy = matchingTimestamp
487+
note.tempDueDate = matchingTimestamp
486488
if shouldDisplay {
487489
currentNotes = append(currentNotes, note)
488490
}

0 commit comments

Comments
 (0)