Skip to content

Commit

Permalink
Add convenience day names when setting due dates
Browse files Browse the repository at this point in the history
  • Loading branch information
gaborbata committed Oct 5, 2020
1 parent 8e76f88 commit fa0dc1a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
20 changes: 13 additions & 7 deletions bin/todo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,8 @@
}

TODAY = DateTime.now

DUE_DATE_DAYS = ['today', 'tomorrow']
(2..6).each do |day|
DUE_DATE_DAYS.push((TODAY.to_date + day).strftime('%A').downcase)
end
DUE_DATE_DAYS = (0..6).map do |day| (TODAY.to_date + day).strftime('%A').downcase end
DUE_DATE_DAYS_SIMPLE = ['today', 'tomorrow']

PRIORITY_FLAG = '*'

Expand Down Expand Up @@ -195,7 +192,12 @@ def set_priority(item)

def due_date(item, date = '')
tasks = load_tasks(item)
tasks[item][:due] = date.nil? || date.empty? ? nil : Date.parse(date).strftime(DATE_FORMAT)
day_index = DUE_DATE_DAYS.index(date.to_s.downcase) || DUE_DATE_DAYS_SIMPLE.index(date.to_s.downcase)
if day_index
tasks[item][:due] = (TODAY.to_date + day_index).strftime(DATE_FORMAT)
else
tasks[item][:due] = date.nil? || date.empty? ? nil : Date.parse(date).strftime(DATE_FORMAT)
end
tasks[item][:modified] = Time.now.strftime(DATE_FORMAT)
write_tasks(tasks)
list(tasks)
Expand Down Expand Up @@ -229,7 +231,7 @@ def list(tasks = nil, patterns = nil)
if date_diff < 0
due_date = colorize("(#{date_diff.abs}d overdue)", :red)
elsif date_diff == 0 || date_diff == 1
due_date = colorize("(#{DUE_DATE_DAYS[date_diff]})", :yellow)
due_date = colorize("(#{DUE_DATE_DAYS_SIMPLE[date_diff]})", :yellow)
else
due_date = colorize("(#{DUE_DATE_DAYS[date_diff] || task[:due]})", :magenta) if date_diff > 1
end
Expand Down Expand Up @@ -291,12 +293,16 @@ def read(arguments)
raise action + ' command requires at least one parameter' if args.nil? || args.empty?
add(args.join(' '))
when 'start'
raise action + ' command can receive only one task number' if args.length > 1
args.length == 1 ? change_state(args.first.to_i, 'started') : list(nil, [':started'])
when 'done'
raise action + ' command can receive only one task number' if args.length > 1
args.length == 1 ? change_state(args.first.to_i, 'done') : list(nil, [':done'])
when 'block'
raise action + ' command can receive only one task number' if args.length > 1
args.length == 1 ? change_state(args.first.to_i, 'blocked') : list(nil, [':blocked'])
when 'reset'
raise action + ' command can receive only one task number' if args.length > 1
args.length == 1 ? change_state(args.first.to_i, 'new') : list(nil, [':new'])
when 'prio'
raise action + ' command requires exactly one parameter' if args.length != 1
Expand Down
2 changes: 1 addition & 1 deletion todo.gemspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Gem::Specification.new do |s|
s.name = 'todo-jsonl'
s.version = '0.1.8'
s.version = '0.1.9'
s.date = '2020-10-05'
s.summary = 'todo list manager inspired by todo.txt using the jsonl format'
s.authors = ['Gabor Bata']
Expand Down

0 comments on commit fa0dc1a

Please sign in to comment.