When sorting on date, tasks with no date go to the end.

This commit is contained in:
Leandro Freitas
2015-04-17 11:31:40 -03:00
parent d0080e66f9
commit e508140f90
3 changed files with 24 additions and 2 deletions

View File

@@ -79,7 +79,9 @@ function! todo#txt#sort_by_project() range
execute a:firstline . "," . a:lastline . "sort /\\(^\\| \\)\\zs+[^[:blank:]]\\+/ r"
endfunction
function! todo#txt#sort_by_date() range
function! todo#txt#sort_by_date() range
let l:date_regex = "\\d\\{2,4\\}-\\d\\{2\\}-\\d\\{2\\}"
execute a:firstline . "," . a:lastline . "sort /" . l:date_regex . "/ r"
execute a:firstline . "," . a:lastline . "g!/" . l:date_regex . "/m" . a:lastline
endfunction

View File

@@ -3,3 +3,10 @@
(B) 2012-04-16 2015-04-16
(A) 2013-03-16 2013-03-10
# end_lorem_ipsum
# task_with_no_date
2013-03-15 task with date
task with no date
2013-03-15 task with date
2013-03-15 task with date
task with no date
# end_task_with_no_date

View File

@@ -10,9 +10,22 @@ let s:SORTED_TASKS = [
\ '(A) 2013-03-16 2013-03-10',
\ ]
function! s:tc.test_sort_by_context()
let s:SORTED_TASKS_WITH_NO_DATE = [
\ '2013-03-15 task with date',
\ '2013-03-15 task with date',
\ '2013-03-15 task with date',
\ 'task with no date',
\ 'task with no date',
\ ]
function! s:tc.test_sort_by_date()
call self.data.visual_execute('call todo#txt#sort_by_date()', 'lorem_ipsum')
call self.assert_equal(s:SORTED_TASKS, self.data.get('lorem_ipsum'))
endfunction
function! s:tc.test_sort_by_date_with_tasks_without_date()
call self.data.visual_execute('call todo#txt#sort_by_date()', 'task_with_no_date')
call self.assert_equal(s:SORTED_TASKS_WITH_NO_DATE, self.data.get('task_with_no_date'))
endfunction
unlet s:tc