Skip to content

Commit

Permalink
Fix for doing done with --took and without --back
Browse files Browse the repository at this point in the history
- FIXED: If doing done is used with --took and without --back, finish
date should be start date plus --took value
  • Loading branch information
ttscoff committed Jul 17, 2021
1 parent 6726ab4 commit 4c70474
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 7 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
### 1.0.62

- Fix: `doing done` with `--took=` and without `--back=` should set end time to start date plus `--took` value

### 1.0.61

- Add --search filter to `doing archive`
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ _Side note:_ I actually use the library behind this utility as part of another s

## Installation

The current version of `doing` is <!--VER-->1.0.60<!--END VER-->.
The current version of `doing` is <!--VER-->1.0.61<!--END VER-->.

$ [sudo] gem install doing

Expand Down
19 changes: 14 additions & 5 deletions bin/doing
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ end

desc 'Add a completed item with @done(date). No argument finishes last entry.'
arg_name 'ENTRY'
command [:done, :did] do |c|
command %i[done did] do |c|
c.desc 'Remove @done tag'
c.switch %i[r remove], negatable: false, default_value: false

Expand Down Expand Up @@ -367,15 +367,17 @@ command [:done, :did] do |c|

date = options[:took] ? finish_date - took : finish_date
elsif options[:took]
finish_date = date + took
finish_date = options[:back] ? date + took : nil
elsif options[:back]
finish_date = date
else
finish_date = Time.now
end

section = wwid.guess_section(options[:s]) || options[:s].cap_first
donedate = options[:date] ? "(#{finish_date.strftime('%F %R')})" : ''
if finish_date
donedate = options[:date] ? "(#{finish_date.strftime('%F %R')})" : ''
end

if options[:e]
raise 'No EDITOR variable defined in environment' if ENV['EDITOR'].nil?
Expand All @@ -394,8 +396,15 @@ command [:done, :did] do |c|
if options[:r]
wwid.tag_last({ tags: ['done'], count: 1, section: section, remove: true })
else
wwid.tag_last({ tags: ['done'], count: 1, section: section, archive: options[:a], back: finish_date,
date: options[:date] })
options = { tags: ['done'],
archive: options[:a],
back: finish_date,
count: 1,
date: options[:date],
section: section,
took: took == 0 ? nil : took
}
wwid.tag_last(options)
end
elsif !args.empty?
title, note = wwid.format_input(args.join(' '))
Expand Down
2 changes: 1 addition & 1 deletion lib/doing/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Doing
VERSION = '1.0.61'
VERSION = '1.0.62'
end
3 changes: 3 additions & 0 deletions lib/doing/wwid.rb
Original file line number Diff line number Diff line change
Expand Up @@ -776,6 +776,7 @@ def tag_last(opt = {})
opt[:remove] ||= false
opt[:autotag] ||= false
opt[:back] ||= false
opt[:took] ||= nil

sec_arr = []

Expand Down Expand Up @@ -833,6 +834,8 @@ def tag_last(opt = {})
else
done_date = item['date'] + (opt[:back] - item['date'])
end
elsif opt[:took]
done_date = item['date'] + opt[:took]
else
done_date = Time.now
end
Expand Down
31 changes: 31 additions & 0 deletions test/doing_chronify_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,37 @@ def test_finish_took
'Finished time should be 60 minutes after start')
end

def test_done_took
now = Time.now
finish = (now - (30 * 60)).round_time(2)
doing('now', '--back', '1h', 'test interval format')
doing('done', '--took', '30m')
r = doing('show').uncolor.strip
d = r.match(ENTRY_DONE_REGEX)
assert(d, 'Entry should have done date')
end_time = Time.parse(d['ts']).round_time(2)
assert_equal(end_time, finish,
'Finish time should be equal to the nearest minute')
end

def test_done_back_took
now = Time.now
start = (now - (30 * 60)).round_time(2)
finish = start + (10 * 60)
doing('done', '--back', '30m', '--took', '10m', 'Test task')
r = doing('show').uncolor.strip
t = r.match(ENTRY_TS_REGEX)
d = r.match(ENTRY_DONE_REGEX)
assert(t, "Entry should have timestamp")
assert(d, 'Entry should have @done with timestamp')
start_time = Time.parse(t['ts']).round_time(2)
end_time = Time.parse(d['ts']).round_time(2)
assert_equal(start_time, start,
'Start time should be equal to the nearest minute')
assert_equal(end_time, finish,
'Finish time should be equal to the nearest minute')
end

private

def mktmpdir
Expand Down

0 comments on commit 4c70474

Please sign in to comment.