Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
O
Openfire
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
Openfire
Commits
9213e6d4
Commit
9213e6d4
authored
Oct 18, 2017
by
Greg Thomas
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve the formatting of the cache expiry time
parent
e06143ab
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
89 additions
and
2 deletions
+89
-2
openfire_i18n_en.properties
src/i18n/openfire_i18n_en.properties
+2
-0
StringUtils.java
src/java/org/jivesoftware/util/StringUtils.java
+49
-1
StringUtilsTest.java
src/test/java/org/jivesoftware/util/StringUtilsTest.java
+37
-0
system-cache.jsp
src/web/system-cache.jsp
+1
-1
No files found.
src/i18n/openfire_i18n_en.properties
View file @
9213e6d4
...
...
@@ -835,6 +835,8 @@ global.main=Main
global.continue
=
Continue
global.none
=
None
global.refresh
=
Refresh
global.millisecond
=
ms
global.milliseconds
=
ms
global.second
=
second
global.seconds
=
seconds
global.minute
=
minute
...
...
src/java/org/jivesoftware/util/StringUtils.java
View file @
9213e6d4
...
...
@@ -841,6 +841,54 @@ public final class StringUtils {
return
zeroPadString
(
Long
.
toString
(
date
.
getTime
()),
15
);
}
/**
* Returns a textual representation for the time that has elapsed.
*
* @param delta the elapsed time in milliseconds
* @return textual representation for the time that has elapsed.
*/
public
static
String
getFullElapsedTime
(
final
long
delta
)
{
if
(
delta
<
JiveConstants
.
SECOND
)
{
return
String
.
format
(
"%d %s"
,
delta
,
delta
==
1
?
LocaleUtils
.
getLocalizedString
(
"global.millisecond"
)
:
LocaleUtils
.
getLocalizedString
(
"global.milliseconds"
));
}
else
if
(
delta
<
JiveConstants
.
MINUTE
)
{
final
long
millis
=
delta
%
JiveConstants
.
SECOND
;
final
long
seconds
=
delta
/
JiveConstants
.
SECOND
;
final
String
secondsString
=
String
.
format
(
"%d %s"
,
seconds
,
seconds
==
1
?
LocaleUtils
.
getLocalizedString
(
"global.second"
)
:
LocaleUtils
.
getLocalizedString
(
"global.seconds"
));
if
(
millis
>
0
)
{
return
secondsString
+
", "
+
getFullElapsedTime
(
millis
);
}
else
{
return
secondsString
;
}
}
else
if
(
delta
<
JiveConstants
.
HOUR
)
{
final
long
millis
=
delta
%
JiveConstants
.
MINUTE
;
final
long
minutes
=
delta
/
JiveConstants
.
MINUTE
;
final
String
minutesString
=
String
.
format
(
"%d %s"
,
minutes
,
minutes
==
1
?
LocaleUtils
.
getLocalizedString
(
"global.minute"
)
:
LocaleUtils
.
getLocalizedString
(
"global.minutes"
));
if
(
millis
>
0
)
{
return
minutesString
+
", "
+
getFullElapsedTime
(
millis
);
}
else
{
return
minutesString
;
}
}
else
if
(
delta
<
JiveConstants
.
DAY
)
{
final
long
millis
=
delta
%
JiveConstants
.
HOUR
;
final
long
hours
=
delta
/
JiveConstants
.
HOUR
;
final
String
daysString
=
String
.
format
(
"%d %s"
,
hours
,
hours
==
1
?
LocaleUtils
.
getLocalizedString
(
"global.hour"
)
:
LocaleUtils
.
getLocalizedString
(
"global.hours"
));
if
(
millis
>
0
)
{
return
daysString
+
", "
+
getFullElapsedTime
(
millis
);
}
else
{
return
daysString
;
}
}
else
{
final
long
millis
=
delta
%
JiveConstants
.
DAY
;
final
long
days
=
delta
/
JiveConstants
.
DAY
;
final
String
daysString
=
String
.
format
(
"%d %s"
,
days
,
days
==
1
?
LocaleUtils
.
getLocalizedString
(
"global.day"
)
:
LocaleUtils
.
getLocalizedString
(
"global.days"
));
if
(
millis
>
0
)
{
return
daysString
+
", "
+
getFullElapsedTime
(
millis
);
}
else
{
return
daysString
;
}
}
}
/**
* Returns a textual representation for the time that has elapsed.
*
...
...
@@ -1105,4 +1153,4 @@ public final class StringUtils {
public
static
String
getString
(
byte
[]
input
)
{
return
new
String
(
input
,
StandardCharsets
.
UTF_8
);
}
}
\ No newline at end of file
}
src/test/java/org/jivesoftware/util/StringUtilsTest.java
View file @
9213e6d4
package
org
.
jivesoftware
.
util
;
import
static
org
.
hamcrest
.
CoreMatchers
.
is
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
static
org
.
junit
.
Assert
.
fail
;
import
org.junit.Test
;
...
...
@@ -55,4 +57,39 @@ public class StringUtilsTest {
//assertEquals("Unexpected cause: " + iae.getMessage(), expectedCause, iae.getMessage());
}
}
@Test
public
void
testElapsedTimeInMilliseconds
()
throws
Exception
{
assertThat
(
StringUtils
.
getFullElapsedTime
(
0
),
is
(
"0 ms"
));
assertThat
(
StringUtils
.
getFullElapsedTime
(
1
),
is
(
"1 ms"
));
assertThat
(
StringUtils
.
getFullElapsedTime
(
250
),
is
(
"250 ms"
));
}
@Test
public
void
testElapsedTimeInSeconds
()
throws
Exception
{
assertThat
(
StringUtils
.
getFullElapsedTime
(
JiveConstants
.
SECOND
),
is
(
"1 second"
));
assertThat
(
StringUtils
.
getFullElapsedTime
(
JiveConstants
.
SECOND
+
1
),
is
(
"1 second, 1 ms"
));
assertThat
(
StringUtils
.
getFullElapsedTime
(
JiveConstants
.
SECOND
*
30
+
30
),
is
(
"30 seconds, 30 ms"
));
}
@Test
public
void
testElapsedTimeInMinutes
()
throws
Exception
{
assertThat
(
StringUtils
.
getFullElapsedTime
(
JiveConstants
.
MINUTE
),
is
(
"1 minute"
));
assertThat
(
StringUtils
.
getFullElapsedTime
(
JiveConstants
.
MINUTE
+
JiveConstants
.
SECOND
+
1
),
is
(
"1 minute, 1 second, 1 ms"
));
assertThat
(
StringUtils
.
getFullElapsedTime
(
JiveConstants
.
MINUTE
*
30
+
JiveConstants
.
SECOND
*
30
),
is
(
"30 minutes, 30 seconds"
));
}
@Test
public
void
testElapsedTimeInHours
()
throws
Exception
{
assertThat
(
StringUtils
.
getFullElapsedTime
(
JiveConstants
.
HOUR
),
is
(
"1 hour"
));
assertThat
(
StringUtils
.
getFullElapsedTime
(
JiveConstants
.
HOUR
+
JiveConstants
.
MINUTE
+
JiveConstants
.
SECOND
+
1
),
is
(
"1 hour, 1 minute, 1 second, 1 ms"
));
assertThat
(
StringUtils
.
getFullElapsedTime
(
JiveConstants
.
HOUR
*
10
+
JiveConstants
.
MINUTE
*
30
),
is
(
"10 hours, 30 minutes"
));
}
@Test
public
void
testElapsedTimeInDays
()
throws
Exception
{
assertThat
(
StringUtils
.
getFullElapsedTime
(
JiveConstants
.
DAY
),
is
(
"1 day"
));
assertThat
(
StringUtils
.
getFullElapsedTime
(
JiveConstants
.
DAY
+
JiveConstants
.
HOUR
+
JiveConstants
.
MINUTE
+
JiveConstants
.
SECOND
+
1
),
is
(
"1 day, 1 hour, 1 minute, 1 second, 1 ms"
));
assertThat
(
StringUtils
.
getFullElapsedTime
(
JiveConstants
.
DAY
*
10
+
JiveConstants
.
HOUR
*
10
),
is
(
"10 days, 10 hours"
));
}
}
src/web/system-cache.jsp
View file @
9213e6d4
...
...
@@ -220,7 +220,7 @@
</td>
<td
class=
"c2"
>
<%
if
(
cache
.
getMaxLifetime
()
!=
-
1
)
{
%>
<%=
cache
.
getMaxLifetime
()
%>
ms
<%=
StringUtils
.
getFullElapsedTime
(
cache
.
getMaxLifetime
())
%>
<%
}
else
{
%>
<fmt:message
key=
"global.unlimited"
/>
<%
}
%>
...
...
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