Welcome to mirror list, hosted at ThFree Co, Russian Federation.

utils.js « logs « javascripts « assets « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 8479eeb3b599a43aafe689d7ed2d96d701cb581a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import { secondsToMilliseconds } from '~/lib/utils/datetime_utility';
import dateFormat from 'dateformat';
import { dateFormatMask } from './constants';

/**
 * Returns a time range (`start`, `end`) where `start` is the
 * current time minus a given number of seconds and `end`
 * is the current time (`now()`).
 *
 * @param {Number} seconds Seconds duration, defaults to 0.
 * @returns {Object} range Time range
 * @returns {String} range.start ISO String of current time minus given seconds
 * @returns {String} range.end ISO String of current time
 */
export const getTimeRange = (seconds = 0) => {
  const end = Math.floor(Date.now() / 1000); // convert milliseconds to seconds
  const start = end - seconds;

  return {
    start: new Date(secondsToMilliseconds(start)).toISOString(),
    end: new Date(secondsToMilliseconds(end)).toISOString(),
  };
};

export const formatDate = timestamp => dateFormat(timestamp, dateFormatMask);

export default {};