benrhughes / todotxt.net

An implementation of todo.txt for Windows using the .NET framework
http://benrhughes.github.io/todotxt.net/
Other
500 stars 123 forks source link

SetTaskDueDate() doesn't work if the due date is at the start of the task #244

Closed Piscean closed 9 years ago

Piscean commented 9 years ago

Around line 916 in MainWindowViewModel.cs, private Task SetTaskDueDate(Task task, dynamic newDueDate) { Regex rgx = new Regex(@"(?<=\sdue:)(?(\d{4})-(\d{2})-(\d{2}))"); string oldDueDateText = rgx.Match(task.Raw).Groups["date"].Value.Trim();

        string oldTaskRawText = task.Raw;
        oldDueDateText = rgx.Match(oldTaskRawText).Groups["date"].Value.Trim();
        string newTaskRawText = (String.IsNullOrEmpty(oldDueDateText)) ?
            oldTaskRawText + " due:" + ((DateTime)newDueDate).ToString("yyyy-MM-dd") :
            rgx.Replace(oldTaskRawText, ((DateTime)newDueDate).ToString("yyyy-MM-dd"));

        return new Task(newTaskRawText);
    }

If you call this with a task like "due:2014-11-20 Whatever text" and attempt to set the new due date to 2014-11-22, it returns this: ""due:2014-11-20 Whatever text due:2014-11-22"

The rgx expression is broken, so it's not finding a match, and then appending the new due date to the end of the string.

Sadly, the regex logic is beyond me to untangle.

mjdescy commented 9 years ago

@Piscean Good catch. I would never write a due date at the start of a task, so I didn't consider coding for that situation. I'm issuing a patch to fix it.

Piscean commented 9 years ago

I'll grab the latest and try it out tomorrow.

The reason I do the due date at the start is because my phone todotxt app is limited in what it can do. Sorting is the only way to tell what I need to do today, so all my tasks start with "due:2014-xx-xx", which means today's tasks are at the top of the list on the phone.

The functionality I was adding to the windows version is "Postpone to Tuesday" instead of Postpone 2 days. I have it all coded and working once these two bugs are fixed. I should be able to check in Monday or Tuesday, assuming all goes well with my testing.