diff --git a/package.json b/package.json index 85355a4488a03..89dc8984fb075 100644 --- a/package.json +++ b/package.json @@ -1727,7 +1727,6 @@ "cypress-network-idle": "^1.14.2", "cypress-real-events": "^1.11.0", "cypress-recurse": "^1.35.2", - "date-fns": "^2.29.3", "dependency-check": "^4.1.0", "dependency-cruiser": "^16.8.0", "ejs": "^3.1.10", diff --git a/packages/kbn-babel-register/BUILD.bazel b/packages/kbn-babel-register/BUILD.bazel index b64bf2eee0d46..1615aa3cf7341 100644 --- a/packages/kbn-babel-register/BUILD.bazel +++ b/packages/kbn-babel-register/BUILD.bazel @@ -35,7 +35,6 @@ BUNDLER_DEPS = [ "@npm//chalk", "@npm//pirates", "@npm//lmdb", - "@npm//date-fns", "@npm//source-map-support", "//src/platform/packages/private/kbn-repo-packages", "//src/platform/packages/shared/kbn-repo-info", diff --git a/packages/kbn-babel-register/cache/lmdb_cache.js b/packages/kbn-babel-register/cache/lmdb_cache.js index f4b5547b47586..e7e5e045ee59b 100644 --- a/packages/kbn-babel-register/cache/lmdb_cache.js +++ b/packages/kbn-babel-register/cache/lmdb_cache.js @@ -9,14 +9,11 @@ const Path = require('path'); const Crypto = require('crypto'); -const startOfDay = /** @type {import('date-fns/startOfDay').default} */ ( - /** @type {unknown} */ (require('date-fns/startOfDay')) -); const chalk = require('chalk'); const LmdbStore = require('lmdb'); -const GLOBAL_ATIME = startOfDay(new Date()).valueOf(); +const GLOBAL_ATIME = new Date().setHours(0, 0, 0, 0); const MINUTE = 1000 * 60; const HOUR = MINUTE * 60; const DAY = HOUR * 24; diff --git a/renovate.json b/renovate.json index b15cf62d6a4f8..7e96fed5facaa 100644 --- a/renovate.json +++ b/renovate.json @@ -3478,26 +3478,6 @@ "minimumReleaseAge": "7 days", "enabled": true }, - { - "groupName": "date-fns", - "matchDepNames": [ - "date-fns" - ], - "reviewers": [ - "team:obs-ux-management-team" - ], - "matchBaseBranches": [ - "main" - ], - "labels": [ - "release_note:skip", - "backport:all-open", - "ci:all-cypress-suites", - "Team:obs-ux-management" - ], - "minimumReleaseAge": "7 days", - "enabled": true - }, { "groupName": "form-data", "matchDepNames": [ diff --git a/src/platform/packages/private/kbn-generate-csv/src/generate_csv.test.ts b/src/platform/packages/private/kbn-generate-csv/src/generate_csv.test.ts index e2999b63088d3..2147e6e50c56a 100644 --- a/src/platform/packages/private/kbn-generate-csv/src/generate_csv.test.ts +++ b/src/platform/packages/private/kbn-generate-csv/src/generate_csv.test.ts @@ -10,7 +10,6 @@ import { identity, range } from 'lodash'; import * as Rx from 'rxjs'; import type { Writable } from 'stream'; -import { add, type Duration } from 'date-fns'; import { errors as esErrors, estypes } from '@elastic/elasticsearch'; import type { SearchResponse } from '@elastic/elasticsearch/lib/api/types'; @@ -38,6 +37,7 @@ import { UI_SETTINGS_DATEFORMAT_TZ, } from '../constants'; import { CsvGenerator } from './generate_csv'; +import moment from 'moment'; type CsvConfigType = ReportingConfigType['csv']; @@ -576,9 +576,9 @@ describe('CsvGenerator', () => { }); describe('export behavior when scroll duration config is auto', () => { - const getTaskInstanceFields = (intervalFromNow: Duration) => { + const getTaskInstanceFields = (intervalFromNow: { seconds: number }) => { const now = new Date(Date.now()); - return { startedAt: now, retryAt: add(now, intervalFromNow) }; + return { startedAt: now, retryAt: moment(now).add(intervalFromNow).toDate() }; }; let mockConfigWithAutoScrollDuration: ReportingConfigType['csv']; diff --git a/src/platform/packages/private/kbn-generate-csv/src/generate_csv_esql.test.ts b/src/platform/packages/private/kbn-generate-csv/src/generate_csv_esql.test.ts index 8dbcfba7bbc9d..b8c4633c17b80 100644 --- a/src/platform/packages/private/kbn-generate-csv/src/generate_csv_esql.test.ts +++ b/src/platform/packages/private/kbn-generate-csv/src/generate_csv_esql.test.ts @@ -9,7 +9,6 @@ import * as Rx from 'rxjs'; import type { Writable } from 'stream'; -import { add, type Duration } from 'date-fns'; import { errors as esErrors } from '@elastic/elasticsearch'; import type { IScopedClusterClient, IUiSettingsClient, Logger } from '@kbn/core/server'; @@ -31,6 +30,7 @@ import { UI_SETTINGS_DATEFORMAT_TZ, } from '../constants'; import { CsvESQLGenerator, JobParamsCsvESQL } from './generate_csv_esql'; +import moment from 'moment'; const createMockJob = (params: JobParamsCsvESQL): JobParamsCsvESQL => ({ ...params, @@ -216,9 +216,9 @@ describe('CsvESQLGenerator', () => { }); describe('"auto" scroll duration config', () => { - const getTaskInstanceFields = (intervalFromNow: Duration) => { + const getTaskInstanceFields = (intervalFromNow: { seconds: number }) => { const now = new Date(Date.now()); - return { startedAt: now, retryAt: add(now, intervalFromNow) }; + return { startedAt: now, retryAt: moment(now).add(intervalFromNow).toDate() }; }; let mockConfigWithAutoScrollDuration: ReportingConfigType['csv']; diff --git a/src/platform/packages/private/kbn-generate-csv/src/lib/get_export_settings.test.ts b/src/platform/packages/private/kbn-generate-csv/src/lib/get_export_settings.test.ts index f1c73680a8b9d..245d78c83883b 100644 --- a/src/platform/packages/private/kbn-generate-csv/src/lib/get_export_settings.test.ts +++ b/src/platform/packages/private/kbn-generate-csv/src/lib/get_export_settings.test.ts @@ -15,7 +15,6 @@ import { } from '@kbn/core/server/mocks'; import type { ReportingConfigType } from '@kbn/reporting-server'; import type { TaskInstanceFields } from '@kbn/reporting-common/types'; -import { sub, add, type Duration } from 'date-fns'; import { UI_SETTINGS_CSV_QUOTE_VALUES, @@ -24,6 +23,7 @@ import { UI_SETTINGS_SEARCH_INCLUDE_FROZEN, } from '../../constants'; import { getExportSettings } from './get_export_settings'; +import moment from 'moment'; describe('getExportSettings', () => { let uiSettingsClient: IUiSettingsClient; @@ -154,7 +154,7 @@ describe('getExportSettings', () => { describe('scroll duration function', () => { let spiedDateNow: jest.Spied; let mockedTaskInstanceFields: TaskInstanceFields; - const durationApart: Duration = { minutes: 5 }; + const durationApart: { minutes: number } = { minutes: 5 }; beforeEach(() => { const now = Date.now(); @@ -163,8 +163,8 @@ describe('getExportSettings', () => { spiedDateNow = jest.spyOn(Date, 'now').mockReturnValue(now); mockedTaskInstanceFields = { - startedAt: sub(new Date(Date.now()), durationApart), - retryAt: add(new Date(Date.now()), durationApart), + startedAt: moment().subtract(durationApart).toDate(), + retryAt: moment().add(durationApart).toDate(), }; }); @@ -238,7 +238,7 @@ describe('getExportSettings', () => { }; spiedDateNow.mockReturnValue( - add(mockedTaskInstanceFields.retryAt!, { minutes: 5 }).getTime() + moment(mockedTaskInstanceFields.retryAt!).add(durationApart).toDate().getTime() ); const { scroll } = await getExportSettings( diff --git a/test/api_integration/apis/home/sample_data.ts b/test/api_integration/apis/home/sample_data.ts index e849c905b2681..ac8d0dcd3e307 100644 --- a/test/api_integration/apis/home/sample_data.ts +++ b/test/api_integration/apis/home/sample_data.ts @@ -9,8 +9,8 @@ import expect from '@kbn/expect'; import type { Response } from 'superagent'; -import differenceInMilliseconds from 'date-fns/differenceInMilliseconds'; import { X_ELASTIC_INTERNAL_ORIGIN_REQUEST } from '@kbn/core-http-common'; +import moment from 'moment'; import { FtrProviderContext } from '../../ftr_provider_context'; export default function ({ getService }: FtrProviderContext) { @@ -75,9 +75,9 @@ export default function ({ getService }: FtrProviderContext) { describe('dates', () => { // dates being compared are not arbitrary, but rather the dates of the earliest and latest timestamp of the flight sample data // this can be verified in the flight data archive here {@link src/platform/plugins/shared/home/server/services/sample_data/data_sets/flights/flights.json.gz} - const sampleDataTimeIntervalInMS = differenceInMilliseconds( - new Date('2018-02-11T14:54:34'), - new Date('2018-01-01T00:00:00') + const sampleDataTimeIntervalInMS = moment('2018-02-11T14:54:34').diff( + moment('2018-01-01T00:00:00'), + 'milliseconds' ); it('should load elasticsearch index containing sample data with dates relative to current time', async () => { diff --git a/x-pack/solutions/observability/plugins/investigate_app/public/pages/details/components/investigation_header/investigation_header.tsx b/x-pack/solutions/observability/plugins/investigate_app/public/pages/details/components/investigation_header/investigation_header.tsx index d6bfb1c496793..cfbfb2f960c68 100644 --- a/x-pack/solutions/observability/plugins/investigate_app/public/pages/details/components/investigation_header/investigation_header.tsx +++ b/x-pack/solutions/observability/plugins/investigate_app/public/pages/details/components/investigation_header/investigation_header.tsx @@ -7,9 +7,8 @@ import { EuiFlexGroup, EuiFlexItem, EuiText } from '@elastic/eui'; import { FormattedMessage } from '@kbn/i18n-react'; -// eslint-disable-next-line import/no-extraneous-dependencies -import { formatDistance } from 'date-fns'; import React from 'react'; +import moment from 'moment'; import { InvestigationStatusBadge } from '../../../../components/investigation_status_badge/investigation_status_badge'; import { InvestigationTag } from '../../../../components/investigation_tag/investigation_tag'; import { useInvestigation } from '../../contexts/investigation_context'; @@ -52,13 +51,7 @@ export function InvestigationHeader() { id="xpack.investigateApp.investigationHeader.startedLabel" defaultMessage="Started: {timeAgo}" values={{ - timeAgo: ( - - {formatDistance(new Date(investigation.createdAt), new Date(), { - addSuffix: true, - })} - - ), + timeAgo: {moment(investigation.createdAt).fromNow()}, }} /> diff --git a/x-pack/solutions/observability/plugins/investigate_app/public/pages/details/components/investigation_notes/note.tsx b/x-pack/solutions/observability/plugins/investigate_app/public/pages/details/components/investigation_notes/note.tsx index d33bca416f5bd..9536bf9562303 100644 --- a/x-pack/solutions/observability/plugins/investigate_app/public/pages/details/components/investigation_notes/note.tsx +++ b/x-pack/solutions/observability/plugins/investigate_app/public/pages/details/components/investigation_notes/note.tsx @@ -15,9 +15,8 @@ import { import { css } from '@emotion/css'; import { InvestigationNoteResponse } from '@kbn/investigation-shared'; import { UserProfile } from '@kbn/security-plugin/common'; -// eslint-disable-next-line import/no-extraneous-dependencies -import { formatDistance } from 'date-fns'; import React, { useState } from 'react'; +import moment from 'moment'; import { useTheme } from '../../../../hooks/use_theme'; import { useInvestigation } from '../../contexts/investigation_context'; import { EditNoteForm } from './edit_note_form'; @@ -78,7 +77,7 @@ export function Note({ note, isOwner, userProfile, userProfileLoading }: Props) - {formatDistance(new Date(note.createdAt), new Date(), { addSuffix: true })} + {moment(new Date(note.createdAt)).fromNow()} diff --git a/yarn.lock b/yarn.lock index 1938e451f6eea..70de5ca0780fd 100644 --- a/yarn.lock +++ b/yarn.lock @@ -16869,11 +16869,6 @@ date-fns@^1.30.1: resolved "https://registry.yarnpkg.com/date-fns/-/date-fns-1.30.1.tgz#2e71bf0b119153dbb4cc4e88d9ea5acfb50dc05c" integrity sha512-hBSVCvSmWC+QypYObzwGOd9wqdDpOt+0wl0KbU+R+uuZBS1jN8VsD1ss3irQDknRj5NvxiTF6oj/nDRnN/UQNw== -date-fns@^2.29.3: - version "2.29.3" - resolved "https://registry.yarnpkg.com/date-fns/-/date-fns-2.29.3.tgz#27402d2fc67eb442b511b70bbdf98e6411cd68a8" - integrity sha512-dDCnyH2WnnKusqvZZ6+jA1O51Ibt8ZMRNkDZdyAyK4YfbDwa/cEmuztzG5pk6hqlp9aSBPYcjOlktquahGwGeA== - date-now@^0.1.4: version "0.1.4" resolved "https://registry.yarnpkg.com/date-now/-/date-now-0.1.4.tgz#eaf439fd4d4848ad74e5cc7dbef200672b9e345b"