Skip to content

Commit

Permalink
Fix minimum_time calculation for non-default values
Browse files Browse the repository at this point in the history
* time intervals are rounded up to the next 'minimum_time'
  step
  • Loading branch information
fheft committed May 3, 2024
1 parent 11c724e commit 15d2030
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/buchungsstreber/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ def parse_time(time_descr)
end

def minimum_time(time, minimum_time_value)
minimum_time = ((time * 60 * 60) / 900).ceil
time_intervals = (time / minimum_time_value).ceil

minimum_time * minimum_time_value
time_intervals * minimum_time_value
end

private
Expand Down
18 changes: 18 additions & 0 deletions spec/parser_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,24 @@
minimum_time = 0.25
expect { described_class.new('../CHANGELOG.md', {}, minimum_time) }.to raise_error(/file extension/)
end

context 'minimum_time' do
subject {
Object.new.extend(Buchungsstreber::TimesheetParser::Base)
}
it 'rounds up to the minimum time interval' do
minimum_time = 0.5
expect(subject.minimum_time(0.75, minimum_time)).to eq(1.0)
end
it 'does not change full intervals' do
minimum_time = 0.5
expect(subject.minimum_time(1.5, minimum_time)).to eq(1.5)
end
it 'handles weird minimal time intervals' do
minimum_time = 0.123
expect(subject.minimum_time(0.1, minimum_time)).to eq(0.123)
end
end
end

class MockParser
Expand Down

0 comments on commit 15d2030

Please sign in to comment.