From 15d2030641d7feaf52b3312ec817f4380b173ceb Mon Sep 17 00:00:00 2001 From: Florian Heft Date: Fri, 3 May 2024 12:41:10 +0200 Subject: [PATCH] Fix minimum_time calculation for non-default values * time intervals are rounded up to the next 'minimum_time' step --- lib/buchungsstreber/parser.rb | 4 ++-- spec/parser_spec.rb | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/lib/buchungsstreber/parser.rb b/lib/buchungsstreber/parser.rb index e66c4e6..a084abc 100644 --- a/lib/buchungsstreber/parser.rb +++ b/lib/buchungsstreber/parser.rb @@ -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 diff --git a/spec/parser_spec.rb b/spec/parser_spec.rb index 911d927..277e270 100644 --- a/spec/parser_spec.rb +++ b/spec/parser_spec.rb @@ -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