Skip to content

Commit

Permalink
improved number formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
greg-junkietech committed Apr 10, 2015
1 parent 11bdb85 commit f83c7ae
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.baloise.confluence.dashboardplus;

import java.io.Serializable;
import java.text.NumberFormat;
import java.util.Date;
import java.util.Map;

Expand Down Expand Up @@ -253,11 +254,13 @@ private void populateVeloContext(Params params,
veloContext.put(VELO_PARAM_NAME_LASTRUNDURATION,
formatDuration(slData.getLastRunDurationInMillis()));

String testInfo = String.valueOf(slData.getTestPassCount());
if (slData.getTestTotalCount() == 0) {
NumberFormat numberFormatter = newNumberFormatter();
String testInfo = numberFormatter.format(slData.getTestPassCount());
if (slData.getTestTotalCount() <= 1) {
testInfo += " test"; //$NON-NLS-1$
} else {
testInfo += "/" + slData.getTestTotalCount()
testInfo += "/"
+ numberFormatter.format(slData.getTestTotalCount())
+ " tests (" //$NON-NLS-1$ //$NON-NLS-2$
+ newPercentFormatter().format(
slData.calcSuccessRatio()) + ")"; //$NON-NLS-1$
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.baloise.confluence.dashboardplus;

import java.io.Serializable;
import java.text.NumberFormat;
import java.util.Date;
import java.util.Map;

Expand Down Expand Up @@ -193,12 +194,13 @@ private void populateVeloContext(Params params,
veloContext.put(VELO_PARAM_NAME_LASTRUNDURATION,
formatDuration(slData.getLastRunDurationInMillis()));

String testInfo = String.valueOf(slData.getTestPassCount());
if (slData.getTestTotalCount() == 0) {
NumberFormat numberFormatter = newNumberFormatter();
String testInfo = numberFormatter.format(slData.getTestPassCount());
if (slData.getTestTotalCount() <= 1) {
testInfo += " test"; //$NON-NLS-1$
} else {
testInfo += "/" //$NON-NLS-1$
+ slData.getTestTotalCount()
+ numberFormatter.format(slData.getTestTotalCount())
+ " tests (" //$NON-NLS-1$
+ newPercentFormatter().format(slData.calcSuccessRatio())
+ ")"; //$NON-NLS-1$
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,4 +176,22 @@ protected FriendlyDateFormatter newFriendlyDateFormatter() {
new Date(), dateFormatter);
return friendlyDateFormatter;
}

protected NumberFormat newNumberFormatter() {
// Get current user's timezone, or default one
User authUser = AuthenticatedUserThreadLocal.getUser();
NumberFormat result = null;
if (authUser != null) {
ConfluenceUserPreferences prefs = userAccessor
.getConfluenceUserPreferences(authUser);
if (prefs != null && prefs.getLocale() != null) {
result = NumberFormat.getNumberInstance(prefs.getLocale());
}
}
if (result == null) {
// anonymous
result = NumberFormat.getNumberInstance();
}
return result;
}
}

0 comments on commit f83c7ae

Please sign in to comment.