Skip to content

Commit

Permalink
Repair selecting one date for display/upload
Browse files Browse the repository at this point in the history
  • Loading branch information
kronn committed Mar 26, 2019
1 parent 9016c0c commit 9682e89
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 9 deletions.
2 changes: 2 additions & 0 deletions gpuzzletime.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ Gem::Specification.new do |spec|

spec.add_development_dependency 'bundler'
spec.add_development_dependency 'overcommit', '~> 0.45'
spec.add_development_dependency 'pry', '~> 0.12'
spec.add_development_dependency 'rake', '~> 10.0'
spec.add_development_dependency 'rspec', '~> 3.0'
spec.add_development_dependency 'rubocop', '~> 0.50'
spec.add_development_dependency 'timecop', '~> 0.9'
end
8 changes: 4 additions & 4 deletions lib/gpuzzletime/app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,10 @@ def url_options(start, entry)

def named_dates(date)
case date
when 'yesterday' then Date.today.prev_day.to_s
when 'today' then Date.today.to_s
when 'last' then parse(read).to_h.keys.compact.sort[-2] || Date.today.prev_day.to_s
when /(\d{2}-){2}-\d{4}/ then date
when 'yesterday' then Date.today.prev_day.to_s
when 'today' then Date.today.to_s
when 'last' then parse(read).to_h.keys.compact.sort[-2] || Date.today.prev_day.to_s
when /\d{4}(-\d{2}){2}/ then date
end
end

Expand Down
37 changes: 32 additions & 5 deletions spec/gpuzzletime/app_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
let(:argument) { 'all' }
let(:timelog) do
<<~TIMELOG
2018-03-02 09:51: start
2018-03-02 09:51: start **
2018-03-02 11:40: 12345: prepare deployment -- webapp
2018-03-02 12:25: lunch **
2018-03-02 13:15: 12345: prepare deployment -- webapp
Expand All @@ -19,11 +19,13 @@
2018-03-02 18:58: break **
2018-03-02 20:08: 12345: prepare deployment -- webapp
2018-03-03 14:00: start
2018-03-03 14:00: start **
2018-03-03 15:34: 23456: debug -- network
2018-03-03 18:46: studying
2018-03-03 20:08: dinner **
2018-03-03 21:36: 12345: prepare deployment -- webapp
2018-03-05 09:00: start **
TIMELOG
end

Expand Down Expand Up @@ -52,9 +54,34 @@
expect { subject.run }.not_to output(/break/).to_stdout
end

# it 'knows today by name'
# it 'knows yesterday by name'
# it 'knows the last day by name'
it 'knows today by name' do
today = '2018-03-03'

Timecop.travel(today) do
expect(subject.send(:named_dates, 'today')).to eq(today)
end
end

it 'knows yesterday by name' do
today = '2018-03-03'
yesterday = '2018-03-02'

Timecop.travel(today) do
expect(subject.send(:named_dates, 'yesterday')).to eq(yesterday)
end
end

it 'knows the last day by name' do
expect(subject).to receive(:read).at_least(:once).and_return(timelog)
last_day = '2018-03-03' # dependent on test-data of timelog above

expect(subject.send(:named_dates, 'last')).to eq(last_day)
end

it 'understands and accepts dates in YYYY-MM-DD format' do
date = '1970-01-01'
expect(subject.send(:named_dates, date)).to be date
end
# it 'defaults to "last day"'

# it 'can show parsed entries'
Expand Down
1 change: 1 addition & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)

require 'gpuzzletime'
require 'timecop'

0 comments on commit 9682e89

Please sign in to comment.