summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/monitoring/utils.js
diff options
context:
space:
mode:
Diffstat (limited to 'app/assets/javascripts/monitoring/utils.js')
-rw-r--r--app/assets/javascripts/monitoring/utils.js32
1 files changed, 15 insertions, 17 deletions
diff --git a/app/assets/javascripts/monitoring/utils.js b/app/assets/javascripts/monitoring/utils.js
index 1dd26f62437..c3e854c5367 100644
--- a/app/assets/javascripts/monitoring/utils.js
+++ b/app/assets/javascripts/monitoring/utils.js
@@ -1,32 +1,30 @@
-import { timeWindows } from './constants';
+import { timeWindows, msPerMinute } from './constants';
export const getTimeDifferenceMinutes = timeWindow => {
- let timeDifferenceMinutes;
switch (timeWindow) {
case timeWindows.thirtyMinutes:
- timeDifferenceMinutes = 30;
- break;
+ return 30;
case timeWindows.threeHours:
- timeDifferenceMinutes = 60 * 3;
- break;
+ return 60 * 3;
case timeWindows.eightHours:
- timeDifferenceMinutes = 60 * 8;
- break;
+ return 60 * 8;
case timeWindows.oneDay:
- timeDifferenceMinutes = 60 * 24 * 1;
- break;
+ return 60 * 24 * 1;
case timeWindows.threeDays:
- timeDifferenceMinutes = 60 * 24 * 3;
- break;
+ return 60 * 24 * 3;
case timeWindows.oneWeek:
- timeDifferenceMinutes = 60 * 24 * 7 * 1;
- break;
+ return 60 * 24 * 7 * 1;
default:
- timeDifferenceMinutes = 60 * 8;
- break;
+ return 60 * 8;
}
+};
+
+export const getTimeDiff = selectedTimeWindow => {
+ const end = Date.now();
+ const timeDifferenceMinutes = getTimeDifferenceMinutes(selectedTimeWindow);
+ const start = new Date(end - timeDifferenceMinutes * msPerMinute).getTime();
- return timeDifferenceMinutes;
+ return { start, end };
};
export default {};