Skip to content
This repository was archived by the owner on Mar 16, 2022. It is now read-only.
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
26 changes: 13 additions & 13 deletions features/due.feature
Original file line number Diff line number Diff line change
Expand Up @@ -15,35 +15,35 @@ Feature: Due
Scenario: List due items
Given the date is "2012-12-12"
And a todofile with the following items exists:
| todo |
| 2012-12-17 Install todotxt @cli +todotxt |
| Read documentation +todotxt |
| 2012-12-12 Buy GTD book @amazon +wishlist |
| 2012-12-19 Evaluate installation +todotxt |
| todo |
| 2012-11-17 Install todotxt due:2012-12-17 @cli +todotxt |
| Read documentation +todotxt |
| Buy GTD book due:2012-12-12 @amazon +wishlist |
| Evaluate installation due:2012-12-19 +todotxt |
When I run `todotxt due` interactively
Then it should pass with exactly:
"""
Due today (2012-12-12)
3. 2012-12-12 Buy GTD book @amazon +wishlist
3. Buy GTD book due:2012-12-12 @amazon +wishlist

Past-due items

Due 7 days in advance
1. 2012-12-17 Install todotxt @cli +todotxt
4. 2012-12-19 Evaluate installation +todotxt
1. 2012-11-17 Install todotxt due:2012-12-17 @cli +todotxt
4. Evaluate installation due:2012-12-19 +todotxt

"""

Scenario: list overdue items
Given the date is "2012-12-12"
And a todofile with the following items exists:
| todo |
| 2012-12-17 Install todotxt @cli +todotxt |
| Read documentation +todotxt |
| 2012-11-11 Buy GTD book @amazon +wishlist |
| todo |
| Install todotxt due:2012-12-17 @cli +todotxt |
| Read documentation +todotxt |
| 2012-10-11 Buy GTD book due:2012-11-11 @amazon +wishlist |
When I run `todotxt due` interactively
Then it should pass with:
"""
Past-due items
3. 2012-11-11 Buy GTD book @amazon +wishlist
3. 2012-10-11 Buy GTD book due:2012-11-11 @amazon +wishlist
"""
2 changes: 2 additions & 0 deletions features/step_definitions/list_steps.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require "date"

Then /^I should see all entries from the todofile with numbers$/ do
step %{I should see all entries from the todofile named "todo.txt" with numbers}
end
Expand Down
2 changes: 1 addition & 1 deletion lib/todotxt/regex.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ module Todotxt
PRIORITY_REGEX = /^\(([A-Z])\) /.freeze
PROJECT_REGEX = /(\+\w+)/.freeze
CONTEXT_REGEX = /(@\w+)/.freeze
DATE_REGEX = /^(\([A-Z]\) )?(x )?((\d{4}-)(\d{1,2}-)(\d{1,2}))\s?/.freeze
DATE_REGEX = /(\s+due:((\d{4}-)(\d{1,2}-)(\d{1,2})))/.freeze
DONE_REGEX = /^(\([A-Z]\) )?x /.freeze
end
2 changes: 1 addition & 1 deletion lib/todotxt/todo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def initialize(text, line = nil)
# Get due date if set
# @return [Date|Nil]
def due
date = Chronic.parse(text.scan(DATE_REGEX).flatten[2])
date = Chronic.parse(text.scan(DATE_REGEX).flatten[1])
date.nil? ? nil : date.to_date
end

Expand Down
9 changes: 5 additions & 4 deletions spec/todo_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,15 @@
expect(todo.done).to be_truthy
end

it 'parses a due date' do
todo = Todotxt::Todo.new '(A) x 2012-12-12 an item +project1 +project2 @context1 @context2'
it 'parses a due: date' do
# prio state completion-date creation-date description ... key:value
todo = Todotxt::Todo.new '(A) x 2012-11-22 2011-11-12 an item due:2012-12-12 +project1 +project2 @context1 @context2'
expect(todo.due).to eql(Chronic.parse('12 December 2012').to_date)

todo = Todotxt::Todo.new '2012-1-2 an item +project1 +project2 @context1 @context2'
todo = Todotxt::Todo.new 'item due:2012-1-2 +project1 +project2 @context1 @context2'
expect(todo.due).to eql(Chronic.parse('2 January 2012').to_date)

todo = Todotxt::Todo.new '42 folders'
todo = Todotxt::Todo.new '2011-31-1 42 folders'
expect(todo.due).to be_nil
end

Expand Down
6 changes: 3 additions & 3 deletions spec/todolist_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,15 @@
end

it 'fetches items for a certain date' do
@list.add '2012-12-12 item'
@list.add 'item due:2012-12-12'
date = DateTime.parse('2012-12-12')
expect(@list.on_date(date).count).to eql 1
expect(@list.on_date(date)).to match([@list.todos.last])
end

it 'fetchs items before a cereain date' do
@list.add '2012-11-11 item'
@list.add '2012-12-12 item'
@list.add 'item due:2012-11-11'
@list.add 'item due:2012-12-12'
date = DateTime.parse('2012-12-12')
expect(@list.before_date(date).count).to eql 1
end
Expand Down