|
|
import { timeWindows, msPerMinute } from './constants';
|
|
import { timeWindows } from './constants';
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* method that converts a predetermined time window to minutes
|
|
* method that converts a predetermined time window to minutes
|
| ... | @@ -6,27 +6,26 @@ import { timeWindows, msPerMinute } from './constants'; |
... | @@ -6,27 +6,26 @@ import { timeWindows, msPerMinute } from './constants'; |
|
|
* @param {String} timeWindow - The time window to convert to minutes
|
|
* @param {String} timeWindow - The time window to convert to minutes
|
|
|
* @returns {number} The time window in minutes
|
|
* @returns {number} The time window in minutes
|
|
|
*/
|
|
*/
|
|
|
const getTimeDifferenceMinutes = timeWindow => {
|
|
const getTimeDifferenceSeconds = timeWindow => {
|
|
|
switch (timeWindow) {
|
|
switch (timeWindow) {
|
|
|
case timeWindows.thirtyMinutes:
|
|
case timeWindows.thirtyMinutes:
|
|
|
return 30;
|
|
return 60 * 30;
|
|
|
case timeWindows.threeHours:
|
|
case timeWindows.threeHours:
|
|
|
return 60 * 3;
|
|
return 60 * 60 * 3;
|
|
|
case timeWindows.oneDay:
|
|
case timeWindows.oneDay:
|
|
|
return 60 * 24 * 1;
|
|
return 60 * 60 * 24 * 1;
|
|
|
case timeWindows.threeDays:
|
|
case timeWindows.threeDays:
|
|
|
return 60 * 24 * 3;
|
|
return 60 * 60 * 24 * 3;
|
|
|
case timeWindows.oneWeek:
|
|
case timeWindows.oneWeek:
|
|
|
return 60 * 24 * 7 * 1;
|
|
return 60 * 60 * 24 * 7 * 1;
|
|
|
default:
|
|
default:
|
|
|
return 60 * 8;
|
|
return 60 * 60 * 8;
|
|
|
}
|
|
}
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
export const getTimeDiff = selectedTimeWindow => {
|
|
export const getTimeDiff = selectedTimeWindow => {
|
|
|
const end = Date.now();
|
|
const end = Date.now() / 1000; // convert milliseconds to seconds
|
|
|
const timeDifferenceMinutes = getTimeDifferenceMinutes(selectedTimeWindow);
|
|
const start = end - getTimeDifferenceSeconds(selectedTimeWindow);
|
|
|
const start = new Date(end - timeDifferenceMinutes * msPerMinute).getTime();
|
|
|
|
|
|
|
|
|
|
return { start, end };
|
|
return { start, end };
|
|
|
};
|
|
};
|
| ... | |
... | |
| ... | | ... | |