Skip to content

Commit

Permalink
Remove unnecessary date/time conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
gaborbata committed Mar 2, 2021
1 parent fd66b29 commit e61cbd8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
10 changes: 5 additions & 5 deletions bin/todo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,8 @@ def usage
end

def setup
@today = Time.now
next_7_days = (0..6).map do |day| (@today.to_date + day) end
@today = Date.today
next_7_days = (0..6).map do |day| @today + day end
@due_date_days = next_7_days.map do |day| day.strftime('%A').downcase end
due_dates_for_queries = next_7_days.map do |day| day.strftime(DATE_FORMAT) end

Expand Down Expand Up @@ -316,7 +316,7 @@ def list(tasks = nil, patterns = nil)
priority_flag = task[:priority] ? colorize(PRIORITY_FLAG, :red) : ' '
due_date = ''
if task[:due] && state != 'done'
date_diff = (Date.parse(task[:due]) - @today.to_date).to_i
date_diff = (Date.strptime(task[:due], DATE_FORMAT) - @today).to_i
if date_diff < 0
due_date = colorize("(#{date_diff.abs}d overdue)", :red)
elsif date_diff == 0 || date_diff == 1
Expand Down Expand Up @@ -379,9 +379,9 @@ def convert_due_date(date = '')
DUE_DATE_DAYS_SIMPLE.index(date.to_s.downcase) ||
@due_date_days.map do |day| day[0..2] end.index(date.to_s.downcase)
if day_index
due = (@today.to_date + day_index).strftime(DATE_FORMAT)
due = (@today + day_index).strftime(DATE_FORMAT)
else
due = date.nil? || date.empty? ? nil : Date.parse(date).strftime(DATE_FORMAT)
due = date.nil? || date.empty? ? nil : Date.strptime(date, DATE_FORMAT).strftime(DATE_FORMAT)
end
return due
end
Expand Down
4 changes: 2 additions & 2 deletions todo.gemspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Gem::Specification.new do |s|
s.name = 'todo-jsonl'
s.version = '0.1.19'
s.date = '2021-03-01'
s.version = '0.1.20'
s.date = '2021-03-02'
s.summary = 'todo list manager inspired by todo.txt using the jsonl format'
s.authors = ['Gabor Bata']
s.homepage = 'https://github.com/gaborbata/todo'
Expand Down

0 comments on commit e61cbd8

Please sign in to comment.