Skip to content
GitLab
Explore
Projects
Groups
Snippets
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
佳 邓
Gitlab4j Api
Commits
a2514940
Commit
a2514940
authored
7 years ago
by
Greg Messner
Browse files
Options
Download
Email Patches
Plain Diff
Added support for w (week) in duration.
parent
c4dd092b
main
5.0.x
5.0.x.jdk17
6.x
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/main/java/org/gitlab4j/api/utils/DurationUtils.java
+17
-5
src/main/java/org/gitlab4j/api/utils/DurationUtils.java
with
17 additions
and
5 deletions
+17
-5
src/main/java/org/gitlab4j/api/utils/DurationUtils.java
+
17
-
5
View file @
a2514940
...
...
@@ -5,8 +5,8 @@ import java.util.regex.Pattern;
public
class
DurationUtils
{
private
static
char
[]
TIME_UNITS
=
{
'd'
,
'h'
,
'm'
,
's'
};
private
static
int
[]
TIME_UNIT_MULTIPLIERS
=
{
60
*
60
*
24
,
60
*
60
,
60
,
1
};
private
static
char
[]
TIME_UNITS
=
{
'w'
,
'd'
,
'h'
,
'm'
,
's'
};
private
static
int
[]
TIME_UNIT_MULTIPLIERS
=
{
60
*
60
*
24
*
7
,
60
*
60
*
24
,
60
*
60
,
60
,
1
};
private
static
Pattern
durationPattern
=
Pattern
.
compile
(
"(\\s*(\\d+)([a-z]))"
);
...
...
@@ -18,14 +18,26 @@ public class DurationUtils {
*/
public
static
final
String
toString
(
int
durationSeconds
)
{
int
days
=
durationSeconds
/
TIME_UNIT_MULTIPLIERS
[
0
];
int
seconds
=
durationSeconds
-
(
days
*
TIME_UNIT_MULTIPLIERS
[
0
]);
int
weeks
=
durationSeconds
/
TIME_UNIT_MULTIPLIERS
[
0
];
int
days
=
(
durationSeconds
-
weeks
*
TIME_UNIT_MULTIPLIERS
[
0
])
/
TIME_UNIT_MULTIPLIERS
[
1
];
int
seconds
=
durationSeconds
-
(
weeks
*
TIME_UNIT_MULTIPLIERS
[
0
])
-
(
days
*
TIME_UNIT_MULTIPLIERS
[
1
]);
int
hours
=
seconds
/
3600
;
int
minutes
=
(
seconds
%
3600
)
/
60
;
seconds
=
seconds
%
60
;
StringBuilder
buf
=
new
StringBuilder
();
if
(
days
>
0
)
{
if
(
weeks
>
0
)
{
buf
.
append
(
weeks
).
append
(
'w'
);
if
(
seconds
>
0
)
{
buf
.
append
(
days
).
append
(
'd'
).
append
(
hours
).
append
(
'h'
).
append
(
minutes
).
append
(
'm'
).
append
(
seconds
).
append
(
's'
);
}
else
if
(
minutes
>
0
)
{
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'
);
if
(
seconds
>
0
)
{
...
...
This diff is collapsed.
Click to expand it.
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
Menu
Explore
Projects
Groups
Snippets