2019-10-28 14:06:15 -04:00
|
|
|
import { getMonthNames } from '~/lib/utils/datetime_utility';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Converts provided string to date and returns formatted value as a year for date in January and month name for the rest
|
|
|
|
* @param {String}
|
|
|
|
* @returns {String} - formatted value
|
|
|
|
*
|
|
|
|
* xAxisLabelFormatter('01-12-2019') will return '2019'
|
|
|
|
* xAxisLabelFormatter('02-12-2019') will return 'Feb'
|
|
|
|
* xAxisLabelFormatter('07-12-2019') will return 'Jul'
|
|
|
|
*/
|
2020-12-23 16:10:24 -05:00
|
|
|
export const xAxisLabelFormatter = (val) => {
|
2019-10-28 14:06:15 -04:00
|
|
|
const date = new Date(val);
|
|
|
|
const month = date.getUTCMonth();
|
|
|
|
const year = date.getUTCFullYear();
|
|
|
|
return month === 0 ? `${year}` : getMonthNames(true)[month];
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Formats provided date to YYYY-MM-DD format
|
|
|
|
* @param {Date}
|
|
|
|
* @returns {String} - formatted value
|
|
|
|
*/
|
2020-12-23 16:10:24 -05:00
|
|
|
export const dateFormatter = (date) => {
|
2019-10-28 14:06:15 -04:00
|
|
|
const year = date.getUTCFullYear();
|
|
|
|
const month = date.getUTCMonth();
|
|
|
|
const day = date.getUTCDate();
|
|
|
|
|
|
|
|
return `${year}-${`0${month + 1}`.slice(-2)}-${`0${day}`.slice(-2)}`;
|
|
|
|
};
|