Commit 0022b6b2 authored by Filipa Lacerda's avatar Filipa Lacerda

Merge branch 'mw-productivity-analytics-utils-init-date-array' into 'master'

Productivity Analytics: Add initDateArray utility method

See merge request gitlab-org/gitlab!18248
parents 6b9ef7ca bf8c7c58
import { getDateInPast } from '~/lib/utils/datetime_utility';
import { getDayDifference, getDateInPast } from '~/lib/utils/datetime_utility';
import { median } from '~/lib/utils/number_utils';
/**
......@@ -29,6 +29,21 @@ export const getMilestonesEndpoint = (namespacePath, projectPathWithNamespace) =
return `/groups/${namespacePath}/-/milestones`;
};
/**
* Computes the day difference 'days' between a given start and end date
* and creates an array of length 'days'.
* For each day in the array it initializes an empty array.
*
* E.g. initDateArray(new Date('2019-01-01'), new Date('2019-01-03'))
* the following data structure gets generated: [ [], [], [] ]
* @param {Date} startDate - The start date
* @param {Date} endDate - The end date
*/
export const initDateArray = (startDate, endDate) => {
const days = getDayDifference(startDate, endDate);
return Array.from({ length: days + 1 }, () => []);
};
/**
* Transforms a given data object into an array
* which will be used as series data for the scatterplot chart.
......
import {
getLabelsEndpoint,
getMilestonesEndpoint,
initDateArray,
getScatterPlotData,
getMedianLineData,
} from 'ee/analytics/productivity_analytics/utils';
......@@ -35,6 +36,15 @@ describe('Productivity Analytics utils', () => {
});
});
describe('initDateArray', () => {
it('creates a two-dimensional array with 3 empty arrays for startDate=2019-09-01 and endDate=2019-09-03', () => {
const startDate = new Date('2019-09-01');
const endDate = new Date('2019-09-03');
expect(initDateArray(startDate, endDate)).toEqual([[], [], []]);
});
});
describe('getScatterPlotData', () => {
it('filters out data before given "dateInPast", transforms the data and sorts by date ascending', () => {
const dateInPast = new Date(2019, 7, 9); // '2019-08-09T22:00:00.000Z';
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment