aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-web
diff options
context:
space:
mode:
Diffstat (limited to 'server/sonar-web')
-rw-r--r--server/sonar-web/src/main/js/apps/background-tasks/__tests__/background-tasks-test.js28
-rw-r--r--server/sonar-web/src/main/js/apps/background-tasks/utils.js23
2 files changed, 30 insertions, 21 deletions
diff --git a/server/sonar-web/src/main/js/apps/background-tasks/__tests__/background-tasks-test.js b/server/sonar-web/src/main/js/apps/background-tasks/__tests__/background-tasks-test.js
index e08e8244b6e..d24841cea10 100644
--- a/server/sonar-web/src/main/js/apps/background-tasks/__tests__/background-tasks-test.js
+++ b/server/sonar-web/src/main/js/apps/background-tasks/__tests__/background-tasks-test.js
@@ -179,36 +179,36 @@ describe('Helpers', () => {
expect(formatDuration(999)).toBe('999ms');
});
- it('should format 1s', () => {
- expect(formatDuration(1000)).toBe('1s');
+ it('should format 1s 0ms', () => {
+ expect(formatDuration(1000)).toBe('1s 0ms');
});
- it('should format 1s', () => {
- expect(formatDuration(1001)).toBe('1s');
+ it('should format 1s 1ms', () => {
+ expect(formatDuration(1001)).toBe('1s 1ms');
});
- it('should format 2s', () => {
- expect(formatDuration(1501)).toBe('2s');
+ it('should format 1s 501ms', () => {
+ expect(formatDuration(1501)).toBe('1s 501ms');
});
it('should format 59s', () => {
expect(formatDuration(59000)).toBe('59s');
});
- it('should format 1min', () => {
- expect(formatDuration(60000)).toBe('1min');
+ it('should format 1min 0s', () => {
+ expect(formatDuration(60000)).toBe('1min 0s');
});
- it('should format 1min', () => {
- expect(formatDuration(62757)).toBe('1min');
+ it('should format 1min 2s', () => {
+ expect(formatDuration(62757)).toBe('1min 2s');
});
- it('should format 4min', () => {
- expect(formatDuration(224567)).toBe('4min');
+ it('should format 3min 44s', () => {
+ expect(formatDuration(224567)).toBe('3min 44s');
});
- it('should format 80min', () => {
- expect(formatDuration(80 * 60 * 1000)).toBe('80min');
+ it('should format 1h 20m', () => {
+ expect(formatDuration(80 * 60 * 1000)).toBe('1h 20min');
});
});
});
diff --git a/server/sonar-web/src/main/js/apps/background-tasks/utils.js b/server/sonar-web/src/main/js/apps/background-tasks/utils.js
index 4d425d33e91..cc32d38c25b 100644
--- a/server/sonar-web/src/main/js/apps/background-tasks/utils.js
+++ b/server/sonar-web/src/main/js/apps/background-tasks/utils.js
@@ -77,6 +77,7 @@ export function mapFiltersToParameters(filters /*: Object */ = {}) {
const ONE_SECOND = 1000;
const ONE_MINUTE = 60 * ONE_SECOND;
+const ONE_HOUR = 60 * ONE_MINUTE;
function format(int, suffix) {
return `${int}${suffix}`;
@@ -86,13 +87,21 @@ export function formatDuration(value /*: ?number */) {
if (!value) {
return '';
}
- if (value >= ONE_MINUTE) {
- const minutes = Math.round(value / ONE_MINUTE);
- return format(minutes, 'min');
- } else if (value >= ONE_SECOND) {
- const seconds = Math.round(value / ONE_SECOND);
- return format(seconds, 's');
- } else {
+ if (value < ONE_SECOND) {
return format(value, 'ms');
+ } else if (value < ONE_SECOND * 10) {
+ const seconds = Math.floor(value / ONE_SECOND);
+ const ms = value - seconds * ONE_SECOND;
+ return format(seconds, 's') + ' ' + format(ms, 'ms');
+ } else if (value < ONE_MINUTE) {
+ const seconds = Math.floor(value / ONE_SECOND);
+ return format(seconds, 's');
+ } else if (value < ONE_MINUTE * 10) {
+ const minutes = Math.floor(value / ONE_MINUTE);
+ const seconds = Math.floor((value - minutes * ONE_MINUTE) / ONE_SECOND);
+ return format(minutes, 'min') + ' ' + format(seconds, 's');
}
+ const hours = Math.floor(value / ONE_HOUR);
+ const minutes = Math.floor((value - hours * ONE_HOUR) / ONE_MINUTE);
+ return format(hours, 'h') + ' ' + format(minutes, 'min');
}