diff options
Diffstat (limited to 'app/assets/javascripts/monitoring/utils.js')
-rw-r--r-- | app/assets/javascripts/monitoring/utils.js | 65 |
1 files changed, 0 insertions, 65 deletions
diff --git a/app/assets/javascripts/monitoring/utils.js b/app/assets/javascripts/monitoring/utils.js index c824d6d4ddb..3847d885f9a 100644 --- a/app/assets/javascripts/monitoring/utils.js +++ b/app/assets/javascripts/monitoring/utils.js @@ -1,68 +1,3 @@ -import dateformat from 'dateformat'; -import { secondsIn, dateTimePickerRegex, dateFormats } from './constants'; -import { secondsToMilliseconds } from '~/lib/utils/datetime_utility'; - -export const getTimeDiff = timeWindow => { - const end = Math.floor(Date.now() / 1000); // convert milliseconds to seconds - const difference = secondsIn[timeWindow] || secondsIn.eightHours; - const start = end - difference; - - return { - start: new Date(secondsToMilliseconds(start)).toISOString(), - end: new Date(secondsToMilliseconds(end)).toISOString(), - }; -}; - -export const getTimeWindow = ({ start, end }) => - Object.entries(secondsIn).reduce((acc, [timeRange, value]) => { - if (new Date(end) - new Date(start) === secondsToMilliseconds(value)) { - return timeRange; - } - return acc; - }, null); - -export const isDateTimePickerInputValid = val => dateTimePickerRegex.test(val); - -export const truncateZerosInDateTime = datetime => datetime.replace(' 00:00:00', ''); - -/** - * The URL params start and end need to be validated - * before passing them down to other components. - * - * @param {string} dateString - */ -export const isValidDate = dateString => { - try { - // dateformat throws error that can be caught. - // This is better than using `new Date()` - if (dateString && dateString.trim()) { - dateformat(dateString, 'isoDateTime'); - return true; - } - return false; - } catch (e) { - return false; - } -}; - -/** - * Convert the input in Time picker component to ISO date. - * - * @param {string} val - * @returns {string} - */ -export const stringToISODate = val => - dateformat(new Date(val.replace(/-/g, '/')), dateFormats.dateTimePicker.ISODate, true); - -/** - * Convert the ISO date received from the URL to string - * for the Time picker component. - * - * @param {Date} date - * @returns {string} - */ -export const ISODateToString = date => dateformat(date, dateFormats.dateTimePicker.stringDate); - /** * This method is used to validate if the graph data format for a chart component * that needs a time series as a response from a prometheus query (query_range) is |