Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Date.vala
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public class GOFI.Date {
GLib.Date b_date = GLib.Date ();

this.dt.get_ymd (out a_year, out a_month, out a_day);
dt.get_ymd (out b_year, out b_month, out b_day);
date.dt.get_ymd (out b_year, out b_month, out b_day);

a_date.set_dmy (
(GLib.DateDay) a_day, (GLib.DateMonth) a_month, (GLib.DateYear) a_year
Expand Down
31 changes: 29 additions & 2 deletions src/Todo.txt/Widgets/TaskRow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -342,10 +342,29 @@ class GOFI.TXT.TaskRow: DragListRow {
var timer_value_str = Utils.seconds_to_pretty_string (timer_value);
new_tooltip_text += "\n%s: %s".printf (_("Timer"), timer_value_str);
}
if (task.due_date != null) {
var due_str = task.due_date.dt.format (date_format);
var days_left = days_until_due ();
if (days_left < 0) {
due_str = _("%s (overdue)").printf (due_str);
} else if (days_left == 0) {
due_str = _("%s (today)").printf (due_str);
}
new_tooltip_text += "\n%s: %s".printf (_("Due"), due_str);
}
this.tooltip_text = new_tooltip_text;
}
}

/**
* Number of days until the task is due, negative if it is overdue.
* Only call this if the task has a due date.
*/
private int days_until_due () {
var today = new GOFI.Date (new GLib.DateTime.now_local ());
return today.days_between (task.due_date);
}

private void gen_markup () {
markup_string = make_links (task.get_descr_parts ());
var str_builder = new StringBuilder.sized (100);
Expand Down Expand Up @@ -379,8 +398,15 @@ class GOFI.TXT.TaskRow: DragListRow {
str_builder.append (TxtUtils.dt_to_string (task.threshold_date.dt));
}
if (task.due_date != null) {
str_builder.append (" due:");
str_builder.append (TxtUtils.dt_to_string (task.due_date.dt));
var due_str = "due:" + TxtUtils.dt_to_string (task.due_date.dt);
var days_left = days_until_due ();
if (done || days_left > 0) {
str_builder.append (" " + due_str);
} else if (days_left == 0) {
str_builder.append (@" <b>$due_str</b>");
} else {
str_builder.append (@" <span foreground=\"#c01c28\"><b>$due_str</b></span>");
}
}
task.append_recurrence_rule (str_builder);

Expand Down Expand Up @@ -450,6 +476,7 @@ class GOFI.TXT.TaskRow: DragListRow {
task.notify["description"].connect (update);
task.notify["priority"].connect (update);
task.notify["timer-value"].connect (update);
task.notify["due-date"].connect (update);
}
}
}
21 changes: 21 additions & 0 deletions tests/todo.txt/TaskManagerTest.vala
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class TaskManagerTest : TestCase {
add_test ("Repeat task 2 days from completion date (due date)", test_reschedule_completion_due_date);
add_test ("Repeat task 2 days from completion date (threshold date)", test_reschedule_completion_threshold_date);
add_test ("Repeat weekly task upon completing", test_reschedule_periodically);
add_test ("Repeat weekly task upon completing (due and threshold date)", test_reschedule_periodically_threshold);
add_test ("Repeat task: every 3 months, skipping past dates", test_reschedule_monthly_skip);
add_test ("Check drift compensation", test_reschedule_monthly_drift_compensation);
add_test ("Repeat task: yearly reschedule", test_yearly_reschedule);
Expand Down Expand Up @@ -301,6 +302,26 @@ class TaskManagerTest : TestCase {
compare_post_schedule (task_copy, completed_task, generated_task, threshold_date, due_date, test_date, test_date);
}

private void test_reschedule_periodically_threshold () {
var task_manager = new TaskManager.test_instance ();
var task = build_test_weekly ();
task.due_date = new GOFI.Date.from_ymd (2021, 11, 16);
task.threshold_date = new GOFI.Date.from_ymd (2021, 11, 14);
var task_copy = task.copy ();
task_manager.todo_store.add_task (task);
var test_date = new GOFI.Date.from_ymd (2021, 11, 15);
task_manager.static_date = test_date.dt;
task.set_completed (test_date);

var completed_task = task_manager.done_store.get_task (0);
var generated_task = task_manager.todo_store.get_task (0);
// The threshold date moves along with the due date
var due_date = new GOFI.Date.from_ymd (2021, 11, 23);
var threshold_date = new GOFI.Date.from_ymd (2021, 11, 21);

compare_post_schedule (task_copy, completed_task, generated_task, threshold_date, due_date, test_date, test_date);
}

private void test_reschedule_monthly_skip () {
var task_manager = new TaskManager.test_instance ();
var task = build_test_3month_skip ();
Expand Down