2020-03-11 11:09:37 -04:00
|
|
|
import { secondsToMilliseconds } from '~/lib/utils/datetime_utility';
|
2020-03-13 08:09:22 -04:00
|
|
|
import dateFormat from 'dateformat';
|
2020-04-13 11:09:20 -04:00
|
|
|
import { dateFormatMask } from './constants';
|
2020-03-11 11:09:37 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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(),
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2020-03-13 08:09:22 -04:00
|
|
|
export const formatDate = timestamp => dateFormat(timestamp, dateFormatMask);
|
|
|
|
|
2020-03-11 11:09:37 -04:00
|
|
|
export default {};
|