From 3ee14b7b735cf1f753742cb5e72f2ec4f53d55ad Mon Sep 17 00:00:00 2001 From: gcornut Date: Thu, 28 Sep 2023 09:53:22 +0200 Subject: [PATCH] chore(core): remove moment and deprecated date-picker utils --- CHANGELOG.md | 4 ++ packages/lumx-core/package.json | 4 -- packages/lumx-core/src/js/date-picker.ts | 77 ------------------------ packages/lumx-core/webpack.config.js | 2 +- packages/site-demo/package.json | 2 - yarn.lock | 20 +----- 6 files changed, 7 insertions(+), 102 deletions(-) delete mode 100644 packages/lumx-core/src/js/date-picker.ts diff --git a/CHANGELOG.md b/CHANGELOG.md index e6c459842..4e737aaa4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Removed + +- _[BREAKING]_ `@lumx/core/js/utils/date-picker` date util functions have been removed, replaced with internal utils (not using moment anymore) + ### Changed - `@lumx/react` no long depend on `moment` or `moment-range` to generate the date picker. diff --git a/packages/lumx-core/package.json b/packages/lumx-core/package.json index 6bafd0f5b..1d621b307 100644 --- a/packages/lumx-core/package.json +++ b/packages/lumx-core/package.json @@ -73,9 +73,5 @@ "webpack": "^4.44.1", "webpack-notifier": "^1.8.0", "webpackbar": "^4.0.0" - }, - "peerDependencies": { - "moment": ">= 2", - "moment-range": "^4.0.2" } } diff --git a/packages/lumx-core/src/js/date-picker.ts b/packages/lumx-core/src/js/date-picker.ts deleted file mode 100644 index 1d223d34d..000000000 --- a/packages/lumx-core/src/js/date-picker.ts +++ /dev/null @@ -1,77 +0,0 @@ -import range from 'lodash/range'; -import mMoment, { Moment } from 'moment'; -import { extendMoment } from 'moment-range'; - -const moment = extendMoment(mMoment as any); - -const DAYS_PER_WEEK = 7; - -interface AnnotatedDate { - date: Moment; - isDisplayed: boolean; - isClickable: boolean; - isToday: boolean; -} - -/** - * Get the list of days in a week based on locale. - * - * @deprecated will be removed in next major version along with the removal of moment (no replacement planned) - * - * @param locale The locale using to generate the order of days in a week. - * @return The list of days in a week based on locale. - */ -export function getWeekDays(locale: string): Moment[] { - return range(DAYS_PER_WEEK).map((_, i) => moment().locale(locale).weekday(i)); -} - -/** - * Get month calendar based on locale and start date. - * - * @deprecated will be removed in next major version along with the removal of moment (no replacement planned) - * - * @param locale The locale using to generate the order of days in a week. - * @param selectedMonth The selected month. - * @return The list of days in a week based on locale. - */ -export function getMonthCalendar(locale: string, selectedMonth?: Moment): Moment[] { - const firstDayOfMonth = moment(selectedMonth).startOf('month'); - const endDayOfMonth = moment(selectedMonth).endOf('month'); - // The first day of the week depends on the locale used. In FR the first day is a monday but in EN the first day is sunday - const firstDay = firstDayOfMonth.locale(locale).startOf('week'); - const monthRange = moment.range(firstDay.toDate(), endDayOfMonth.toDate()); - - return Array.from(monthRange.by('day')); -} - -/** - * Get month calendar based on locale and start date. - * Each day is annotated to know if they are displayed and/or clickable. - * - * @deprecated will be removed in next major version along with the removal of moment (no replacement planned) - * - * @param locale The locale using to generate the order of days in a week. - * @param minDate The first selectable date. - * @param maxDate The last selectable date. - * @param selectedMonth The selected month. - * @return The list of days in a week based on locale. - */ -export function getAnnotatedMonthCalendar( - locale: string, - minDate?: Date, - maxDate?: Date, - selectedMonth?: Moment, -): AnnotatedDate[] { - const month = moment(selectedMonth).locale(locale).month(); - - const clickableRange = moment.range(minDate as Date, maxDate as Date); - - return getMonthCalendar(locale, selectedMonth).map((date) => { - return { - date, - isClickable: clickableRange.contains(date), - isDisplayed: date.month() === month, - isToday: date.isSame(moment(), 'day'), - }; - }); -} diff --git a/packages/lumx-core/webpack.config.js b/packages/lumx-core/webpack.config.js index 1453a0b25..2e2aec795 100644 --- a/packages/lumx-core/webpack.config.js +++ b/packages/lumx-core/webpack.config.js @@ -143,7 +143,7 @@ module.exports = { ), }, - externals: ['moment', 'moment-range'], + externals: [], bail: true, devtool: 'source-map', diff --git a/packages/site-demo/package.json b/packages/site-demo/package.json index f958c2659..8fa9b3794 100644 --- a/packages/site-demo/package.json +++ b/packages/site-demo/package.json @@ -44,8 +44,6 @@ "intersection-observer": "^0.7.0", "lodash": "4.17.21", "lunr": "^2.3.9", - "moment": "^2.29.4", - "moment-range": "^4.0.2", "prism-react-renderer": "^0.1.5", "prismjs": "^1.25.0", "react": "^17.0.2", diff --git a/yarn.lock b/yarn.lock index 2add57d12..9aa76fdaf 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6100,9 +6100,6 @@ __metadata: webpack: ^4.44.1 webpack-notifier: ^1.8.0 webpackbar: ^4.0.0 - peerDependencies: - moment: ">= 2" - moment-range: ^4.0.2 languageName: unknown linkType: soft @@ -15357,7 +15354,7 @@ __metadata: languageName: node linkType: hard -"es6-symbol@npm:^3.1.0, es6-symbol@npm:^3.1.1, es6-symbol@npm:~3.1.2": +"es6-symbol@npm:^3.1.1, es6-symbol@npm:~3.1.2": version: 3.1.3 resolution: "es6-symbol@npm:3.1.3" dependencies: @@ -23889,8 +23886,6 @@ fsevents@~2.1.2: intersection-observer: ^0.7.0 lodash: 4.17.21 lunr: ^2.3.9 - moment: ^2.29.4 - moment-range: ^4.0.2 prism-react-renderer: ^0.1.5 prismjs: ^1.25.0 react: ^17.0.2 @@ -25016,18 +25011,7 @@ fsevents@~2.1.2: languageName: node linkType: hard -"moment-range@npm:^4.0.2": - version: 4.0.2 - resolution: "moment-range@npm:4.0.2" - dependencies: - es6-symbol: ^3.1.0 - peerDependencies: - moment: ">= 2" - checksum: ff7425eed2600b1450ae25a7d074fb1edbc7956199f9eca974d5b2bc7885912dd08205e55675eb1b8cbbdcb3647622748861822580bd7327e680ca2202f8ee31 - languageName: node - linkType: hard - -"moment@npm:^2.27.0, moment@npm:^2.29.4": +"moment@npm:^2.27.0": version: 2.29.4 resolution: "moment@npm:2.29.4" checksum: 0ec3f9c2bcba38dc2451b1daed5daded747f17610b92427bebe1d08d48d8b7bdd8d9197500b072d14e326dd0ccf3e326b9e3d07c5895d3d49e39b6803b76e80e