Merge branch 'drop-allow_overflow-option-duration_in_numbers' into 'master'
Drop allow overflow option duration in numbers Closes #52284 See merge request gitlab-org/gitlab-ce!22246
This commit is contained in:
commit
fdcdc36eec
6 changed files with 25 additions and 39 deletions
|
@ -21,17 +21,15 @@ module TimeHelper
|
||||||
"#{from.to_s(:short)} - #{to.to_s(:short)}"
|
"#{from.to_s(:short)} - #{to.to_s(:short)}"
|
||||||
end
|
end
|
||||||
|
|
||||||
def duration_in_numbers(duration_in_seconds, allow_overflow = false)
|
def duration_in_numbers(duration_in_seconds)
|
||||||
if allow_overflow
|
|
||||||
seconds = duration_in_seconds % 1.minute
|
seconds = duration_in_seconds % 1.minute
|
||||||
minutes = (duration_in_seconds / 1.minute) % (1.hour / 1.minute)
|
minutes = (duration_in_seconds / 1.minute) % (1.hour / 1.minute)
|
||||||
hours = duration_in_seconds / 1.hour
|
hours = duration_in_seconds / 1.hour
|
||||||
|
|
||||||
"%02d:%02d:%02d" % [hours, minutes, seconds]
|
if hours == 0
|
||||||
|
"%02d:%02d" % [minutes, seconds]
|
||||||
else
|
else
|
||||||
time_format = duration_in_seconds < 1.hour ? "%M:%S" : "%H:%M:%S"
|
"%02d:%02d:%02d" % [hours, minutes, seconds]
|
||||||
|
|
||||||
Time.at(duration_in_seconds).utc.strftime(time_format)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -108,7 +108,7 @@
|
||||||
.btn.btn-default.has-tooltip{ disabled: true,
|
.btn.btn-default.has-tooltip{ disabled: true,
|
||||||
title: job.scheduled_at }
|
title: job.scheduled_at }
|
||||||
= sprite_icon('planning')
|
= sprite_icon('planning')
|
||||||
= duration_in_numbers(job.execute_in, true)
|
= duration_in_numbers(job.execute_in)
|
||||||
- confirmation_message = s_("DelayedJobs|Are you sure you want to run %{job_name} immediately? This job will run automatically after it's timer finishes.") % { job_name: job.name }
|
- confirmation_message = s_("DelayedJobs|Are you sure you want to run %{job_name} immediately? This job will run automatically after it's timer finishes.") % { job_name: job.name }
|
||||||
= link_to play_project_job_path(job.project, job, return_to: request.original_url),
|
= link_to play_project_job_path(job.project, job, return_to: request.original_url),
|
||||||
method: :post,
|
method: :post,
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
title: Drop `allow_overflow` option in `TimeHelper.duration_in_numbers`
|
||||||
|
merge_request: 52284
|
||||||
|
author:
|
||||||
|
type: changed
|
|
@ -29,7 +29,7 @@ module Gitlab
|
||||||
|
|
||||||
def execute_in
|
def execute_in
|
||||||
remaining_seconds = [0, subject.scheduled_at - Time.now].max
|
remaining_seconds = [0, subject.scheduled_at - Time.now].max
|
||||||
duration_in_numbers(remaining_seconds, true)
|
duration_in_numbers(remaining_seconds)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -22,34 +22,17 @@ describe TimeHelper do
|
||||||
describe "#duration_in_numbers" do
|
describe "#duration_in_numbers" do
|
||||||
using RSpec::Parameterized::TableSyntax
|
using RSpec::Parameterized::TableSyntax
|
||||||
|
|
||||||
context "without passing allow_overflow" do
|
|
||||||
where(:duration, :formatted_string) do
|
where(:duration, :formatted_string) do
|
||||||
0 | "00:00"
|
0 | "00:00"
|
||||||
1.second | "00:01"
|
1.second | "00:01"
|
||||||
42.seconds | "00:42"
|
42.seconds | "00:42"
|
||||||
2.minutes + 1.second | "02:01"
|
2.minutes + 1.second | "02:01"
|
||||||
3.hours + 2.minutes + 1.second | "03:02:01"
|
3.hours + 2.minutes + 1.second | "03:02:01"
|
||||||
30.hours | "06:00:00"
|
30.hours | "30:00:00"
|
||||||
end
|
end
|
||||||
|
|
||||||
with_them do
|
with_them do
|
||||||
it { expect(duration_in_numbers(duration)).to eq formatted_string }
|
it { expect(duration_in_numbers(duration)).to eq formatted_string }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context "with allow_overflow = true" do
|
|
||||||
where(:duration, :formatted_string) do
|
|
||||||
0 | "00:00:00"
|
|
||||||
1.second | "00:00:01"
|
|
||||||
42.seconds | "00:00:42"
|
|
||||||
2.minutes + 1.second | "00:02:01"
|
|
||||||
3.hours + 2.minutes + 1.second | "03:02:01"
|
|
||||||
30.hours | "30:00:00"
|
|
||||||
end
|
|
||||||
|
|
||||||
with_them do
|
|
||||||
it { expect(duration_in_numbers(duration, true)).to eq formatted_string }
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -26,9 +26,9 @@ describe Gitlab::Ci::Status::Build::Scheduled do
|
||||||
context 'when scheduled_at is expired' do
|
context 'when scheduled_at is expired' do
|
||||||
let(:build) { create(:ci_build, :expired_scheduled, project: project) }
|
let(:build) { create(:ci_build, :expired_scheduled, project: project) }
|
||||||
|
|
||||||
it 'shows 00:00:00' do
|
it 'shows 00:00' do
|
||||||
Timecop.freeze do
|
Timecop.freeze do
|
||||||
expect(subject.status_tooltip).to include('00:00:00')
|
expect(subject.status_tooltip).to include('00:00')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue