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
a2514940
Commit
a2514940
authored
Oct 23, 2017
by
Greg Messner
Browse files
Added support for w (week) in duration.
parent
c4dd092b
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/main/java/org/gitlab4j/api/utils/DurationUtils.java
View file @
a2514940
...
@@ -5,8 +5,8 @@ import java.util.regex.Pattern;
...
@@ -5,8 +5,8 @@ import java.util.regex.Pattern;
public
class
DurationUtils
{
public
class
DurationUtils
{
private
static
char
[]
TIME_UNITS
=
{
'd'
,
'h'
,
'm'
,
's'
};
private
static
char
[]
TIME_UNITS
=
{
'w'
,
'd'
,
'h'
,
'm'
,
's'
};
private
static
int
[]
TIME_UNIT_MULTIPLIERS
=
{
60
*
60
*
24
,
60
*
60
,
60
,
1
};
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]))"
);
private
static
Pattern
durationPattern
=
Pattern
.
compile
(
"(\\s*(\\d+)([a-z]))"
);
...
@@ -18,14 +18,26 @@ public class DurationUtils {
...
@@ -18,14 +18,26 @@ public class DurationUtils {
*/
*/
public
static
final
String
toString
(
int
durationSeconds
)
{
public
static
final
String
toString
(
int
durationSeconds
)
{
int
days
=
durationSeconds
/
TIME_UNIT_MULTIPLIERS
[
0
];
int
weeks
=
durationSeconds
/
TIME_UNIT_MULTIPLIERS
[
0
];
int
seconds
=
durationSeconds
-
(
days
*
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
hours
=
seconds
/
3600
;
int
minutes
=
(
seconds
%
3600
)
/
60
;
int
minutes
=
(
seconds
%
3600
)
/
60
;
seconds
=
seconds
%
60
;
seconds
=
seconds
%
60
;
StringBuilder
buf
=
new
StringBuilder
();
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'
);
buf
.
append
(
days
).
append
(
'd'
);
if
(
seconds
>
0
)
{
if
(
seconds
>
0
)
{
...
...
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