Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
clients
java
duniter4j
Commits
c72029ae
Commit
c72029ae
authored
Jun 01, 2022
by
Benoit Lavenier
Browse files
[enh] Add DateUtils.elapsedTime() , useful for log
parent
c8283dcd
Pipeline
#15815
failed with stage
in 32 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
duniter4j-core-shared/src/main/java/org/duniter/core/util/DateUtils.java
View file @
c72029ae
...
...
@@ -85,4 +85,24 @@ public class DateUtils {
return
nextDayAndHour
(
dayOfTheWeek
,
hour
).
getTime
()
-
System
.
currentTimeMillis
();
}
public
static
String
elapsedTime
(
long
timeInMs
)
{
long
elapsedTime
=
System
.
currentTimeMillis
()
-
timeInMs
;
StringBuilder
sb
=
new
StringBuilder
();
sb
.
append
(
"in "
);
if
(
elapsedTime
<
1000
)
{
return
sb
.
append
(
elapsedTime
).
append
(
"ms"
).
toString
();
}
double
seconds
=
(
double
)
elapsedTime
/
1_000
;
if
(
seconds
<
60
)
{
return
sb
.
append
(
seconds
).
append
(
"s"
).
toString
();
}
int
minutesFloor
=
(
int
)
Math
.
floor
(
seconds
/
60
);
int
secondsFloor
=
(
int
)
Math
.
floor
(
seconds
-
minutesFloor
*
60
);
int
millis
=
(
int
)
Math
.
floor
((
seconds
-
secondsFloor
-
minutesFloor
*
60
)
*
1_000
);
return
sb
.
append
(
minutesFloor
).
append
(
"min "
)
.
append
(
secondsFloor
).
append
(
"s "
)
.
append
(
millis
).
append
(
"ms"
)
.
toString
();
}
}
Write
Preview
Supports
Markdown
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