Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix minimum_time calculation for non-default values #125

Merged
merged 1 commit into from
May 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading