Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
佳 邓
Gitlab4j Api
Commits
81cc9791
Commit
81cc9791
authored
Jan 07, 2018
by
Greg Messner
Browse files
Fixed issue with dropping days (#114).
parent
a1bb0e65
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/main/java/org/gitlab4j/api/utils/DurationUtils.java
View file @
81cc9791
...
...
@@ -75,6 +75,8 @@ public class DurationUtils {
buf
.
append
(
days
).
append
(
'd'
).
append
(
hours
).
append
(
'h'
).
append
(
minutes
).
append
(
'm'
);
}
else
if
(
hours
>
0
)
{
buf
.
append
(
days
).
append
(
'd'
).
append
(
hours
).
append
(
'h'
);
}
else
if
(
days
>
0
)
{
buf
.
append
(
days
).
append
(
'd'
);
}
}
else
if
(
days
>
0
)
{
...
...
src/test/java/org/gitlab4j/api/TestDuration.java
View file @
81cc9791
...
...
@@ -3,6 +3,7 @@ package org.gitlab4j.api;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
fail
;
import
org.gitlab4j.api.models.Duration
;
import
org.gitlab4j.api.utils.DurationUtils
;
import
org.junit.Test
;
...
...
@@ -27,6 +28,29 @@ public class TestDuration {
assertEquals
(
60
*
60
,
seconds
);
}
@Test
public
void
testRoundTrip
()
{
Duration
duration
=
new
Duration
(
"2mo1d"
);
String
durationString
=
DurationUtils
.
toString
(
duration
.
getSeconds
(),
false
);
assertEquals
(
"8w1d"
,
durationString
);
duration
=
new
Duration
(
durationString
);
assertEquals
(
"2mo1d"
,
duration
.
toString
());
duration
=
new
Duration
(
"9w2h5m"
);
durationString
=
DurationUtils
.
toString
(
duration
.
getSeconds
(),
false
);
assertEquals
(
"9w0d2h5m"
,
durationString
);
duration
=
new
Duration
(
durationString
);
assertEquals
(
"2mo1w0d2h5m"
,
duration
.
toString
());
duration
=
new
Duration
(
"2mo1w1d2h5m"
);
durationString
=
DurationUtils
.
toString
(
duration
.
getSeconds
(),
false
);
assertEquals
(
"9w1d2h5m"
,
durationString
);
duration
=
new
Duration
(
durationString
);
assertEquals
(
"2mo1w1d2h5m"
,
duration
.
toString
());
}
@Test
public
void
testParseWithSpaces
()
{
...
...
@@ -108,5 +132,8 @@ public class TestDuration {
duration
=
DurationUtils
.
toString
(
60
*
60
*
8
*
5
*
4
*
3
+
60
*
60
*
8
*
2
+
60
*
60
*
3
+
60
*
6
+
8
,
false
);
assertEquals
(
"12w2d3h6m8s"
,
duration
);
duration
=
DurationUtils
.
toString
(
60
*
60
*
8
*
5
*
5
+
60
*
60
*
8
*
2
+
60
*
60
*
3
+
60
*
4
+
5
,
false
);
assertEquals
(
"5w2d3h4m5s"
,
duration
);
}
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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