Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
gitlab-ce
Commits
dd4f50b1
Commit
dd4f50b1
authored
Jul 18, 2016
by
Rémy Coutable
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix build duration when build is not finished yet
Signed-off-by:
Rémy Coutable
<
remy@rymai.me
>
parent
017ae313
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
26 additions
and
29 deletions
+26
-29
app/helpers/time_helper.rb
app/helpers/time_helper.rb
+13
-13
app/views/projects/builds/_sidebar.html.haml
app/views/projects/builds/_sidebar.html.haml
+1
-1
app/views/projects/generic_commit_statuses/_generic_commit_status.html.haml
.../generic_commit_statuses/_generic_commit_status.html.haml
+1
-1
spec/helpers/time_helper_spec.rb
spec/helpers/time_helper_spec.rb
+11
-14
No files found.
app/helpers/time_helper.rb
View file @
dd4f50b1
module
TimeHelper
module
TimeHelper
def
duration_in_words
(
finished_at
,
started_at
)
if
finished_at
&&
started_at
interval_in_seconds
=
finished_at
.
to_i
-
started_at
.
to_i
elsif
started_at
interval_in_seconds
=
Time
.
now
.
to_i
-
started_at
.
to_i
end
time_interval_in_words
(
interval_in_seconds
)
end
def
time_interval_in_words
(
interval_in_seconds
)
def
time_interval_in_words
(
interval_in_seconds
)
minutes
=
interval_in_seconds
/
60
minutes
=
interval_in_seconds
/
60
seconds
=
interval_in_seconds
-
minutes
*
60
seconds
=
interval_in_seconds
-
minutes
*
60
...
@@ -25,9 +15,19 @@ module TimeHelper
...
@@ -25,9 +15,19 @@ module TimeHelper
end
end
def
duration_in_numbers
(
finished_at
,
started_at
)
def
duration_in_numbers
(
finished_at
,
started_at
)
diff_in_seconds
=
finished_at
.
to_i
-
started_at
.
to_i
interval
=
interval_in_seconds
(
started_at
,
finished_at
)
time_format
=
diff_in_seconds
<
1
.
hour
?
"%M:%S"
:
"%H:%M:%S"
time_format
=
interval
<
1
.
hour
?
"%M:%S"
:
"%H:%M:%S"
Time
.
at
(
diff_in_seconds
).
utc
.
strftime
(
time_format
)
Time
.
at
(
interval
).
utc
.
strftime
(
time_format
)
end
private
def
interval_in_seconds
(
started_at
,
finished_at
=
nil
)
if
started_at
&&
finished_at
finished_at
.
to_i
-
started_at
.
to_i
elsif
started_at
Time
.
now
.
to_i
-
started_at
.
to_i
end
end
end
end
end
app/views/projects/builds/_sidebar.html.haml
View file @
dd4f50b1
...
@@ -49,7 +49,7 @@
...
@@ -49,7 +49,7 @@
-
if
@build
.
duration
-
if
@build
.
duration
%p
.build-detail-row
%p
.build-detail-row
%span
.build-light-text
Duration:
%span
.build-light-text
Duration:
#{
duration_in_words
(
@build
.
finished_at
,
@build
.
started_at
)
}
=
time_interval_in_words
(
@build
.
duration
)
-
if
@build
.
finished_at
-
if
@build
.
finished_at
%p
.build-detail-row
%p
.build-detail-row
%span
.build-light-text
Finished:
%span
.build-light-text
Finished:
...
...
app/views/projects/generic_commit_statuses/_generic_commit_status.html.haml
View file @
dd4f50b1
...
@@ -51,7 +51,7 @@
...
@@ -51,7 +51,7 @@
%td
.duration
%td
.duration
-
if
generic_commit_status
.
duration
-
if
generic_commit_status
.
duration
=
icon
(
"clock-o"
)
=
icon
(
"clock-o"
)
#{
duration_in_words
(
generic_commit_status
.
finished_at
,
generic_commit_status
.
started_at
)
}
=
time_interval_in_words
(
generic_commit_status
.
duration
)
%td
.timestamp
%td
.timestamp
-
if
generic_commit_status
.
finished_at
-
if
generic_commit_status
.
finished_at
...
...
spec/helpers/time_helper_spec.rb
View file @
dd4f50b1
require
'spec_helper'
require
'spec_helper'
describe
TimeHelper
do
describe
TimeHelper
do
describe
"#
duration
_in_words"
do
describe
"#
time_interval
_in_words"
do
it
"returns minutes and seconds"
do
it
"returns minutes and seconds"
do
intervals_in_words
=
{
intervals_in_words
=
{
100
=>
"1 minute 40 seconds"
,
100
=>
"1 minute 40 seconds"
,
...
@@ -11,26 +11,23 @@ describe TimeHelper do
...
@@ -11,26 +11,23 @@ describe TimeHelper do
}
}
intervals_in_words
.
each
do
|
interval
,
expectation
|
intervals_in_words
.
each
do
|
interval
,
expectation
|
expect
(
duration_in_words
(
Time
.
now
+
interval
,
Time
.
now
)).
to
eq
(
expectation
)
expect
(
time_interval_in_words
(
interval
)).
to
eq
(
expectation
)
end
end
end
end
it
"calculates interval from now if there is no finished_at"
do
expect
(
duration_in_words
(
nil
,
Time
.
now
-
5
)).
to
eq
(
"5 seconds"
)
end
end
end
describe
"#
time_interval_in_word
s"
do
describe
"#
duration_in_number
s"
do
it
"returns minutes and seconds"
do
it
"returns minutes and seconds"
do
intervals_in_words
=
{
duration_in_numbers
=
{
100
=>
"1 minute 40 seconds"
,
[
100
,
0
]
=>
"01:40"
,
121
=>
"2 minutes 1 second"
,
[
121
,
0
]
=>
"02:01"
,
3721
=>
"62 minutes 1 second"
,
[
3721
,
0
]
=>
"01:02:01"
,
0
=>
"0 seconds"
[
0
,
0
]
=>
"00:00"
,
[
nil
,
Time
.
now
.
to_i
-
42
]
=>
"00:42"
}
}
intervals_in_word
s
.
each
do
|
interval
,
expectation
|
duration_in_number
s
.
each
do
|
interval
,
expectation
|
expect
(
time_interval_in_words
(
interval
)).
to
eq
(
expectation
)
expect
(
duration_in_numbers
(
*
interval
)).
to
eq
(
expectation
)
end
end
end
end
end
end
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment