Merge branch '59729-estimate-quick-action-does-not-produce-correct-time-for-1mo' into 'master'
Resolve "estimate quick action does not produce correct time for 1mo" See merge request gitlab-org/gitlab-ce!32165
This commit is contained in:
commit
913c87c612
5 changed files with 79 additions and 0 deletions
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
title: Fix parsing of months in time tracking commands
|
||||||
|
merge_request: 32165
|
||||||
|
author:
|
||||||
|
type: fixed
|
|
@ -1 +1,5 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
ChronicDuration.raise_exceptions = true
|
ChronicDuration.raise_exceptions = true
|
||||||
|
|
||||||
|
ChronicDuration.prepend Gitlab::Patch::ChronicDuration
|
||||||
|
|
35
lib/gitlab/patch/chronic_duration.rb
Normal file
35
lib/gitlab/patch/chronic_duration.rb
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
# Fixes a bug where parsing months doesn't take into account
|
||||||
|
# the ChronicDuration.days_per_week setting
|
||||||
|
#
|
||||||
|
# We can remove this when we do a refactor and push upstream in
|
||||||
|
# https://gitlab.com/gitlab-org/gitlab-ce/issues/66637
|
||||||
|
|
||||||
|
module Gitlab
|
||||||
|
module Patch
|
||||||
|
module ChronicDuration
|
||||||
|
extend ActiveSupport::Concern
|
||||||
|
|
||||||
|
class_methods do
|
||||||
|
def duration_units_seconds_multiplier(unit)
|
||||||
|
return 0 unless duration_units_list.include?(unit)
|
||||||
|
|
||||||
|
case unit
|
||||||
|
when 'months'
|
||||||
|
3600 * ::ChronicDuration.hours_per_day * ::ChronicDuration.days_per_month
|
||||||
|
else
|
||||||
|
super
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# ChronicDuration#output uses 1mo = 4w as the conversion so we do the same here.
|
||||||
|
# We do need to add a special case for the default days_per_week value because
|
||||||
|
# we want to retain existing behavior for the default case
|
||||||
|
def days_per_month
|
||||||
|
::ChronicDuration.days_per_week == 7 ? 30 : ::ChronicDuration.days_per_week * 4
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
27
spec/lib/gitlab/patch/chronic_duration_spec.rb
Normal file
27
spec/lib/gitlab/patch/chronic_duration_spec.rb
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
require 'spec_helper'
|
||||||
|
|
||||||
|
describe Gitlab::Patch::ChronicDuration do
|
||||||
|
subject { ChronicDuration.parse('1mo') }
|
||||||
|
|
||||||
|
it 'uses default conversions' do
|
||||||
|
expect(subject).to eq(2_592_000)
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'with custom conversions' do
|
||||||
|
before do
|
||||||
|
ChronicDuration.hours_per_day = 8
|
||||||
|
ChronicDuration.days_per_week = 5
|
||||||
|
end
|
||||||
|
|
||||||
|
after do
|
||||||
|
ChronicDuration.hours_per_day = 24
|
||||||
|
ChronicDuration.days_per_week = 7
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'uses custom conversions' do
|
||||||
|
expect(subject).to eq(576_000)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -17,6 +17,14 @@ describe Gitlab::TimeTrackingFormatter do
|
||||||
|
|
||||||
it { expect(subject).to eq(-12_000) }
|
it { expect(subject).to eq(-12_000) }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'durations with months' do
|
||||||
|
let(:duration_string) { '1mo' }
|
||||||
|
|
||||||
|
it 'uses our custom conversions' do
|
||||||
|
expect(subject).to eq(576_000)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#output' do
|
describe '#output' do
|
||||||
|
|
Loading…
Reference in a new issue