diff --git a/app/assets/javascripts/analytics/cycle_analytics/utils.js b/app/assets/javascripts/analytics/cycle_analytics/utils.js index d7c3804113e86c27f14386c2f8a7c07c1d28efcb..4456ffb272cfd39c5d4b90630c78d799fdd20d33 100644 --- a/app/assets/javascripts/analytics/cycle_analytics/utils.js +++ b/app/assets/javascripts/analytics/cycle_analytics/utils.js @@ -1,5 +1,5 @@ import { extractVSAFeaturesFromGON } from '~/analytics/shared/utils'; -import { parseSeconds } from '~/lib/utils/datetime_utility'; +import { parseSeconds, newDate } from '~/lib/utils/datetime_utility'; import { formatTimeAsSummary } from '~/lib/utils/datetime/date_format_utility'; import { joinPaths } from '~/lib/utils/url_utility'; @@ -86,8 +86,8 @@ export const buildCycleAnalyticsInitialData = ({ name: namespaceName, fullPath: namespaceFullPath, }, - createdAfter: new Date(createdAfter), - createdBefore: new Date(createdBefore), + createdAfter: newDate(createdAfter), + createdBefore: newDate(createdBefore), selectedStage: stage ? JSON.parse(stage) : null, features: extractVSAFeaturesFromGON(), }; diff --git a/ee/app/assets/javascripts/analytics/shared/utils.js b/ee/app/assets/javascripts/analytics/shared/utils.js index 3db5408fe72b8fa12a903956d451b369dcb52906..d7c4f05601235ebf7b5ceb1cb582f27ae8c2e331 100644 --- a/ee/app/assets/javascripts/analytics/shared/utils.js +++ b/ee/app/assets/javascripts/analytics/shared/utils.js @@ -7,7 +7,7 @@ import { parseBoolean, roundOffFloat, } from '~/lib/utils/common_utils'; -import { getDateInFuture } from '~/lib/utils/datetime/date_calculation_utility'; +import { getDateInFuture, newDate } from '~/lib/utils/datetime/date_calculation_utility'; import { capitalizeFirstCharacter } from '~/lib/utils/text_utility'; import { DEFAULT_NULL_SERIES_OPTIONS, DEFAULT_SERIES_DATA_OPTIONS } from './constants'; @@ -78,22 +78,6 @@ export const buildProjectFromDataset = (dataset) => { return null; }; -/** - * Creates a new date object without time zone conversion. - * - * We use this method instead of `new Date(date)`. - * `new Date(date) will assume that the date string is UTC and it - * ant return different date depending on the user's time zone. - * - * @param {String} date - Date string. - * @returns {Date} - Date object. - */ -export const toLocalDate = (date) => { - const dateParts = date.split('-'); - - return new Date(dateParts[0], dateParts[1] - 1, dateParts[2]); -}; - /** * Creates an array of project objects from a json string. Returns null if no projects are present. * @@ -155,8 +139,8 @@ export const buildCycleAnalyticsInitialData = ({ ) : null, groupPath: groupPath || groupFullPath, - createdBefore: createdBefore ? toLocalDate(createdBefore) : null, - createdAfter: createdAfter ? toLocalDate(createdAfter) : null, + createdBefore: createdBefore ? newDate(createdBefore) : null, + createdAfter: createdAfter ? newDate(createdAfter) : null, selectedProjects: projects ? buildProjectsFromJSON(projects).map((proj) => ({ ...convertObjectPropsToCamelCase(proj), diff --git a/ee/spec/frontend/analytics/shared/utils_spec.js b/ee/spec/frontend/analytics/shared/utils_spec.js index cfab34d5257d33181af8ec45981a4f84b5aeaca5..26af045b52b7eabab2b3364e0e381af0125ba05a 100644 --- a/ee/spec/frontend/analytics/shared/utils_spec.js +++ b/ee/spec/frontend/analytics/shared/utils_spec.js @@ -3,7 +3,6 @@ import { buildProjectFromDataset, buildCycleAnalyticsInitialData, buildNullSeries, - toLocalDate, pairDataAndLabels, linearRegression, } from 'ee/analytics/shared/utils'; @@ -86,14 +85,6 @@ describe('buildProjectFromDataset', () => { }); }); -describe('toLocalDate', () => { - it('returns a Date object', () => { - const expectedDate = new Date(2022, 1, 10); // month is zero-based - - expect(toLocalDate('2022-02-10')).toEqual(expectedDate); - }); -}); - describe('buildCycleAnalyticsInitialData', () => { it.each` field | value