From 90690f4b6a4c8f8a7a221ddc1df69077384f48a9 Mon Sep 17 00:00:00 2001 From: Ghislain B Date: Sun, 28 Apr 2024 01:36:47 -0400 Subject: [PATCH] feat(common)!: migrate from `moment` to `moment-tiny` (#1456) * feat(common): migrate from `moment` to `moment-tiny` - so I created yet another repo, it is very similar to `moment-mini` except that it includes both CJS and ESM builds (which actually both come from the Moment project), however `moment-mini` only includes the CJS build. --- .../vite-demo-vanilla-bundle/package.json | 2 +- .../src/examples/example10.ts | 2 +- .../src/examples/example11.ts | 2 +- package.json | 2 +- packages/common/package.json | 2 +- .../commonEditorFilterUtils.ts | 8 +- .../src/editors/__tests__/dateEditor.spec.ts | 2 +- packages/common/src/editors/dateEditor.ts | 12 ++- .../dateEuroShortFilterCondition.spec.ts | 95 +++++++++++++------ .../dateUsShortFilterCondition.spec.ts | 20 ++-- .../filterConditionProcesses.spec.ts | 2 +- .../filter-conditions/dateFilterCondition.ts | 7 +- .../__tests__/compoundDateFilter.spec.ts | 46 ++++----- packages/common/src/filters/dateFilter.ts | 16 ++-- .../__tests__/dateEuroShortFormatter.spec.ts | 6 +- .../dateTimeEuroShortAM_PMFormatter.spec.ts | 6 +- .../dateTimeEuroShortAmPmFormatter.spec.ts | 6 +- .../dateTimeEuroShortFormatter.spec.ts | 6 +- .../dateTimeUsShortAM_PMFormatter.spec.ts | 6 +- .../dateTimeUsShortAmPmFormatter.spec.ts | 6 +- .../dateTimeUsShortFormatter.spec.ts | 6 +- .../__tests__/dateUsShortFormatter.spec.ts | 6 +- .../src/formatters/formatterUtilities.ts | 7 +- .../src/services/__tests__/utilities.spec.ts | 16 ++-- packages/common/src/services/utilities.ts | 33 ++++--- .../dateEuroShortSortComparer.spec.ts | 16 ++-- .../__tests__/dateUsShortSortComparer.spec.ts | 16 ++-- .../common/src/sortComparers/dateUtilities.ts | 17 ++-- packages/custom-footer-component/package.json | 2 +- .../src/slick-footer.component.ts | 2 +- packages/excel-export/package.json | 2 +- packages/graphql/package.json | 2 +- .../__tests__/graphqlQueryBuilder.spec.ts | 2 +- packages/vanilla-bundle/src/index.ts | 2 +- packages/vanilla-force-bundle/src/index.ts | 2 +- pnpm-lock.yaml | 40 ++++---- test/cypress/e2e/example02.cy.ts | 2 +- test/cypress/e2e/example10.cy.ts | 2 +- test/cypress/e2e/example11.cy.ts | 2 +- test/jest-global-mocks.ts | 4 +- 40 files changed, 240 insertions(+), 195 deletions(-) diff --git a/examples/vite-demo-vanilla-bundle/package.json b/examples/vite-demo-vanilla-bundle/package.json index cff29a19a..bfbe74855 100644 --- a/examples/vite-demo-vanilla-bundle/package.json +++ b/examples/vite-demo-vanilla-bundle/package.json @@ -27,7 +27,7 @@ "bulma": "^1.0.0", "fetch-jsonp": "^1.3.0", "isomorphic-dompurify": "^2.7.0", - "moment-mini": "^2.29.4", + "moment-tiny": "^2.30.3", "multiple-select-vanilla": "^3.1.0", "rxjs": "^7.8.1", "vanilla-calendar-picker": "^2.11.2", diff --git a/examples/vite-demo-vanilla-bundle/src/examples/example10.ts b/examples/vite-demo-vanilla-bundle/src/examples/example10.ts index 6563d2dc0..de452dee5 100644 --- a/examples/vite-demo-vanilla-bundle/src/examples/example10.ts +++ b/examples/vite-demo-vanilla-bundle/src/examples/example10.ts @@ -13,8 +13,8 @@ import { import { BindingEventService } from '@slickgrid-universal/binding'; import { GraphqlService, type GraphqlPaginatedResult, type GraphqlServiceApi, type GraphqlServiceOption, } from '@slickgrid-universal/graphql'; import { Slicker, type SlickVanillaGridBundle } from '@slickgrid-universal/vanilla-bundle'; -import moment from 'moment-mini'; import { type MultipleSelectOption } from 'multiple-select-vanilla'; +import moment from 'moment-tiny'; import { ExampleGridOptions } from './example-grid-options'; import type { TranslateService } from '../translate.service'; diff --git a/examples/vite-demo-vanilla-bundle/src/examples/example11.ts b/examples/vite-demo-vanilla-bundle/src/examples/example11.ts index 8cdb0ba1d..ee875ac47 100644 --- a/examples/vite-demo-vanilla-bundle/src/examples/example11.ts +++ b/examples/vite-demo-vanilla-bundle/src/examples/example11.ts @@ -27,8 +27,8 @@ import { BindingEventService } from '@slickgrid-universal/binding'; import { SlickCustomTooltip } from '@slickgrid-universal/custom-tooltip-plugin'; import { ExcelExportService } from '@slickgrid-universal/excel-export'; import { Slicker, type SlickVanillaGridBundle } from '@slickgrid-universal/vanilla-bundle'; -import moment from 'moment-mini'; import { type MultipleSelectOption } from 'multiple-select-vanilla'; +import moment from 'moment-tiny'; import exampleModal from './example11-modal.html?raw'; import Example11Modal from './example11-modal'; diff --git a/package.json b/package.json index 8638b4398..3030b3a9e 100644 --- a/package.json +++ b/package.json @@ -81,7 +81,7 @@ "jest-extended": "^4.0.2", "jsdom": "^24.0.0", "jsdom-global": "^3.0.2", - "moment-mini": "^2.29.4", + "moment-tiny": "^2.30.3", "npm-run-all2": "^6.1.2", "pnpm": "^8.15.7", "rimraf": "^5.0.5", diff --git a/packages/common/package.json b/packages/common/package.json index 08fb73bef..ba164fb25 100644 --- a/packages/common/package.json +++ b/packages/common/package.json @@ -76,7 +76,7 @@ "dequal": "^2.0.3", "excel-builder-vanilla": "3.0.1", "isomorphic-dompurify": "^2.7.0", - "moment-mini": "^2.29.4", + "moment-tiny": "^2.30.3", "multiple-select-vanilla": "^3.1.0", "sortablejs": "^1.15.2", "un-flatten-tree": "^2.0.12", diff --git a/packages/common/src/commonEditorFilter/commonEditorFilterUtils.ts b/packages/common/src/commonEditorFilter/commonEditorFilterUtils.ts index 149de8f4c..4650ec100 100644 --- a/packages/common/src/commonEditorFilter/commonEditorFilterUtils.ts +++ b/packages/common/src/commonEditorFilter/commonEditorFilterUtils.ts @@ -1,7 +1,6 @@ import type { AutocompleteItem } from 'autocompleter'; import type { IOptions } from 'vanilla-calendar-picker'; -import * as moment_ from 'moment-mini'; -const moment = (moment_ as any)['default'] || moment_; +import moment from 'moment-tiny'; import type { AutocompleterOption, Column, ColumnEditor, ColumnFilter } from '../interfaces/index'; import { formatDateByFieldType, mapMomentDateFormatWithFieldType } from '../services'; @@ -38,7 +37,7 @@ export function setPickerDates(dateInputElm: HTMLInputElement, pickerOptions: IO const currentDateOrDates = dateValues; const outputFieldType = columnDef.outputType || colEditorOrFilter.type || columnDef.type || FieldType.dateUtc; const inputFieldType = colEditorOrFilter.type || columnDef.type; - const isoFormat = mapMomentDateFormatWithFieldType(FieldType.dateIso); + const isoFormat = mapMomentDateFormatWithFieldType(FieldType.dateIso) as string; const inputFormat = inputFieldType ? mapMomentDateFormatWithFieldType(inputFieldType) : ''; const initialDates = Array.isArray(currentDateOrDates) ? currentDateOrDates : [(currentDateOrDates || '') as string]; if (initialDates.length && initialDates[0]) { @@ -48,11 +47,12 @@ export function setPickerDates(dateInputElm: HTMLInputElement, pickerOptions: IO pickerDates.push(momentDate); } + const singleinputFormat = Array.isArray(inputFormat) ? inputFormat[0] : inputFormat; pickerOptions.settings!.selected = { dates: [pickerDates.map(p => p.format(isoFormat)).join(':')], month: pickerDates[0].month(), year: pickerDates[0].year(), - time: inputFormat.toLowerCase().includes('h') ? pickerDates[0].format('HH:mm') : null, + time: singleinputFormat.toLowerCase().includes('h') ? pickerDates[0].format('HH:mm') : undefined, }; dateInputElm.value = initialDates.length ? pickerDates.map(p => formatDateByFieldType(p, undefined, outputFieldType)).join(' — ') : ''; } diff --git a/packages/common/src/editors/__tests__/dateEditor.spec.ts b/packages/common/src/editors/__tests__/dateEditor.spec.ts index b0c8d206b..6f04501dc 100644 --- a/packages/common/src/editors/__tests__/dateEditor.spec.ts +++ b/packages/common/src/editors/__tests__/dateEditor.spec.ts @@ -1,4 +1,4 @@ -import moment from 'moment-mini'; +import moment from 'moment-tiny'; import { VanillaCalendar } from 'vanilla-calendar-picker'; import { Editors } from '../index'; diff --git a/packages/common/src/editors/dateEditor.ts b/packages/common/src/editors/dateEditor.ts index 4665008d5..ca4faa5b0 100644 --- a/packages/common/src/editors/dateEditor.ts +++ b/packages/common/src/editors/dateEditor.ts @@ -1,8 +1,7 @@ import { BindingEventService } from '@slickgrid-universal/binding'; import { createDomElement, emptyElement, extend, setDeepValue } from '@slickgrid-universal/utils'; import { VanillaCalendar, type IOptions } from 'vanilla-calendar-picker'; -import * as moment_ from 'moment-mini'; -const moment = (moment_ as any)['default'] || moment_; +import moment from 'moment-tiny'; import { Constants } from './../constants'; import { FieldType } from '../enums/index'; @@ -110,7 +109,10 @@ export class DateEditor implements Editor { const gridOptions = (this.args.grid.getOptions() || {}) as GridOption; this.defaultDate = this.args.item?.[this.columnDef.field]; const outputFieldType = this.columnDef.outputType || this.columnEditor.type || this.columnDef.type || FieldType.dateUtc; - const outputFormat = mapMomentDateFormatWithFieldType(outputFieldType); + let outputFormat = mapMomentDateFormatWithFieldType(outputFieldType); + if (Array.isArray(outputFormat)) { + outputFormat = outputFormat[0]; + } const currentLocale = this._translaterService?.getCurrentLanguage?.() || gridOptions.locale || 'en'; // add the time picker when format is UTC (Z) or has the 'h' (meaning hours) @@ -140,8 +142,8 @@ export class DateEditor implements Editor { if (this.hasTimePicker) { const momentDate = moment(chosenDate, pickerFormat); - momentDate.hours(self.selectedHours); - momentDate.minute(self.selectedMinutes); + momentDate.hours(+(self.selectedHours || 0)); + momentDate.minute(+(self.selectedMinutes || 0)); self.HTMLInputElement.value = formatDateByFieldType(momentDate, undefined, outputFieldType); } diff --git a/packages/common/src/filter-conditions/__tests__/dateEuroShortFilterCondition.spec.ts b/packages/common/src/filter-conditions/__tests__/dateEuroShortFilterCondition.spec.ts index f8b7e49cc..0d8d5c4b3 100644 --- a/packages/common/src/filter-conditions/__tests__/dateEuroShortFilterCondition.spec.ts +++ b/packages/common/src/filter-conditions/__tests__/dateEuroShortFilterCondition.spec.ts @@ -74,38 +74,77 @@ describe('dateEuroShortFilterCondition method', () => { expect(output).toBe(false); }); - it('should return True when input value is in the range of search terms', () => { - const searchTerms = ['01/12/93..31/12/93']; - const options = { dataKey: '', operator: 'EQ', cellValue: '25/12/93', fieldType: FieldType.dateEuroShort, searchTerms } as FilterConditionOption; - const output = executeFilterConditionTest(options, getFilterParsedDates(searchTerms, FieldType.dateEuroShort)); - expect(output).toBe(true); - }); + describe('without zero padding dates', () => { + it('should return True when input value is in the range of search terms with short US dates and without zero padding', () => { + const searchTerms = ['1/12/93..31/12/93']; + const options = { dataKey: '', operator: 'EQ', cellValue: '25/12/93', fieldType: FieldType.dateEuroShort, searchTerms } as FilterConditionOption; + const output = executeFilterConditionTest(options, getFilterParsedDates(searchTerms, FieldType.dateEuroShort)); + expect(output).toBe(true); + }); - it('should return False when input value is not in the range of search terms', () => { - const searchTerms = ['01/12/93..31/12/93']; - const options = { dataKey: '', operator: 'EQ', cellValue: '25/11/93', fieldType: FieldType.dateEuroShort, searchTerms } as FilterConditionOption; - const output = executeFilterConditionTest(options, getFilterParsedDates(searchTerms, FieldType.dateEuroShort)); - expect(output).toBe(false); - }); + it('should return False when input value is not in the range of search terms with short US dates and without zero padding', () => { + const searchTerms = ['1/12/93..31/12/93']; + const options = { dataKey: '', operator: 'EQ', cellValue: '25/11/93', fieldType: FieldType.dateEuroShort, searchTerms } as FilterConditionOption; + const output = executeFilterConditionTest(options, getFilterParsedDates(searchTerms, FieldType.dateEuroShort)); + expect(output).toBe(false); + }); - it('should return True when input value equals the search terms min inclusive value and operator is set to "rangeInclusive"', () => { - const searchTerms = ['01/12/93..31/12/93']; - const options = { dataKey: '', operator: 'RangeInclusive', cellValue: '01/12/93', fieldType: FieldType.dateEuroShort, searchTerms } as FilterConditionOption; - const output = executeFilterConditionTest(options, getFilterParsedDates(searchTerms, FieldType.dateEuroShort)); - expect(output).toBe(true); - }); + it('should return True when input value equals the search terms min inclusive value and operator is set to "rangeInclusive"', () => { + const searchTerms = ['1/12/93..31/12/93']; + const options = { dataKey: '', operator: 'RangeInclusive', cellValue: '1/12/93', fieldType: FieldType.dateEuroShort, searchTerms } as FilterConditionOption; + const output = executeFilterConditionTest(options, getFilterParsedDates(searchTerms, FieldType.dateEuroShort)); + expect(output).toBe(true); + }); - it('should return False when input value equals the search terms min inclusive value and operator is set to "RangeExclusive"', () => { - const searchTerms = ['01/12/93..31/12/93']; - const options = { dataKey: '', operator: 'RangeExclusive', cellValue: '01/12/93', fieldType: FieldType.dateEuroShort, searchTerms } as FilterConditionOption; - const output = executeFilterConditionTest(options, getFilterParsedDates(searchTerms, FieldType.dateEuroShort)); - expect(output).toBe(false); + it('should return False when input value equals the search terms min inclusive value and operator is set to "RangeExclusive"', () => { + const searchTerms = ['1/12/93..31/12/93']; + const options = { dataKey: '', operator: 'RangeExclusive', cellValue: '1/12/93', fieldType: FieldType.dateEuroShort, searchTerms } as FilterConditionOption; + const output = executeFilterConditionTest(options, getFilterParsedDates(searchTerms, FieldType.dateEuroShort)); + expect(output).toBe(false); + }); + + it('should return False when any of the 2 search term value is not a valid date', () => { + const searchTerms = ['1/12/93..60/12/93']; + const options = { dataKey: '', operator: 'RangeExclusive', cellValue: '05/12/93', fieldType: FieldType.dateEuroShort, searchTerms } as FilterConditionOption; + const output = executeFilterConditionTest(options, getFilterParsedDates(searchTerms, FieldType.dateEuroShort)); + expect(output).toBe(false); + }); }); - it('should return False when any of the 2 search term value is not a valid date', () => { - const searchTerms = ['01/12/93..60/12/93']; - const options = { dataKey: '', operator: 'RangeExclusive', cellValue: '05/12/93', fieldType: FieldType.dateEuroShort, searchTerms } as FilterConditionOption; - const output = executeFilterConditionTest(options, getFilterParsedDates(searchTerms, FieldType.dateEuroShort)); - expect(output).toBe(false); + describe('zero padding dates', () => { + it('should return True when input value is in the range of search terms', () => { + const searchTerms = ['01/12/93..31/12/93']; + const options = { dataKey: '', operator: 'EQ', cellValue: '25/12/93', fieldType: FieldType.dateEuroShort, searchTerms } as FilterConditionOption; + const output = executeFilterConditionTest(options, getFilterParsedDates(searchTerms, FieldType.dateEuroShort)); + expect(output).toBe(true); + }); + + it('should return False when input value is not in the range of search terms', () => { + const searchTerms = ['01/12/93..31/12/93']; + const options = { dataKey: '', operator: 'EQ', cellValue: '25/11/93', fieldType: FieldType.dateEuroShort, searchTerms } as FilterConditionOption; + const output = executeFilterConditionTest(options, getFilterParsedDates(searchTerms, FieldType.dateEuroShort)); + expect(output).toBe(false); + }); + + it('should return True when input value equals the search terms min inclusive value and operator is set to "rangeInclusive"', () => { + const searchTerms = ['01/12/93..31/12/93']; + const options = { dataKey: '', operator: 'RangeInclusive', cellValue: '1/12/93', fieldType: FieldType.dateEuroShort, searchTerms } as FilterConditionOption; + const output = executeFilterConditionTest(options, getFilterParsedDates(searchTerms, FieldType.dateEuroShort)); + expect(output).toBe(true); + }); + + it('should return False when input value equals the search terms min inclusive value and operator is set to "RangeExclusive"', () => { + const searchTerms = ['01/12/93..31/12/93']; + const options = { dataKey: '', operator: 'RangeExclusive', cellValue: '1/12/93', fieldType: FieldType.dateEuroShort, searchTerms } as FilterConditionOption; + const output = executeFilterConditionTest(options, getFilterParsedDates(searchTerms, FieldType.dateEuroShort)); + expect(output).toBe(false); + }); + + it('should return False when any of the 2 search term value is not a valid date', () => { + const searchTerms = ['01/12/93..60/12/93']; + const options = { dataKey: '', operator: 'RangeExclusive', cellValue: '05/12/93', fieldType: FieldType.dateEuroShort, searchTerms } as FilterConditionOption; + const output = executeFilterConditionTest(options, getFilterParsedDates(searchTerms, FieldType.dateEuroShort)); + expect(output).toBe(false); + }); }); }); diff --git a/packages/common/src/filter-conditions/__tests__/dateUsShortFilterCondition.spec.ts b/packages/common/src/filter-conditions/__tests__/dateUsShortFilterCondition.spec.ts index ad6149193..deaa413d4 100644 --- a/packages/common/src/filter-conditions/__tests__/dateUsShortFilterCondition.spec.ts +++ b/packages/common/src/filter-conditions/__tests__/dateUsShortFilterCondition.spec.ts @@ -40,14 +40,14 @@ describe('dateUsShortFilterCondition method', () => { }); it('should return False when cell value is not the same value as the searchTerm', () => { - const searchTerms = ['03/03/2003']; + const searchTerms = ['3/3/2003']; const options = { dataKey: '', operator: 'EQ', fieldType: FieldType.dateUsShort, cellValue: '12/25/93', searchTerms } as FilterConditionOption; const output = executeFilterConditionTest(options, getFilterParsedDates(searchTerms, FieldType.dateUsShort)); expect(output).toBe(false); }); it('should return False even when the cell value is found in the searchTerms since it only compares first term', () => { - const searchTerms = ['03/14/03', '12/25/93']; + const searchTerms = ['3/14/03', '12/25/93']; const options = { dataKey: '', operator: 'EQ', fieldType: FieldType.dateUsShort, cellValue: '12/25/93', searchTerms } as FilterConditionOption; const output = executeFilterConditionTest(options, getFilterParsedDates(searchTerms, FieldType.dateUsShort)); expect(output).toBe(false); @@ -82,36 +82,36 @@ describe('dateUsShortFilterCondition method', () => { }); it('should return True when input value is in the range of search terms', () => { - const searchTerms = ['12/01/93..12/31/93']; + const searchTerms = ['12/1/93..12/31/93']; const options = { dataKey: '', operator: 'EQ', cellValue: '12/25/93', fieldType: FieldType.dateUsShort, searchTerms } as FilterConditionOption; const output = executeFilterConditionTest(options, getFilterParsedDates(searchTerms, FieldType.dateUsShort)); expect(output).toBe(true); }); it('should return False when input value is not in the range of search terms', () => { - const searchTerms = ['12/01/93..12/31/93']; + const searchTerms = ['12/1/93..12/31/93']; const options = { dataKey: '', operator: 'EQ', cellValue: '11/25/93', fieldType: FieldType.dateUsShort, searchTerms } as FilterConditionOption; const output = executeFilterConditionTest(options, getFilterParsedDates(searchTerms, FieldType.dateUsShort)); expect(output).toBe(false); }); it('should return True when input value equals the search terms min inclusive value and operator is set to "rangeInclusive"', () => { - const searchTerms = ['12/01/93..12/31/93']; - const options = { dataKey: '', operator: 'RangeInclusive', cellValue: '12/01/93', fieldType: FieldType.dateUsShort, searchTerms } as FilterConditionOption; + const searchTerms = ['12/1/93..12/31/93']; + const options = { dataKey: '', operator: 'RangeInclusive', cellValue: '12/1/93', fieldType: FieldType.dateUsShort, searchTerms } as FilterConditionOption; const output = executeFilterConditionTest(options, getFilterParsedDates(searchTerms, FieldType.dateUsShort)); expect(output).toBe(true); }); it('should return False when input value equals the search terms min inclusive value and operator is set to "RangeExclusive"', () => { - const searchTerms = ['12/01/93..12/31/93']; - const options = { dataKey: '', operator: 'RangeExclusive', cellValue: '12/01/93', fieldType: FieldType.dateUsShort, searchTerms } as FilterConditionOption; + const searchTerms = ['12/1/93..12/31/93']; + const options = { dataKey: '', operator: 'RangeExclusive', cellValue: '12/1/93', fieldType: FieldType.dateUsShort, searchTerms } as FilterConditionOption; const output = executeFilterConditionTest(options, getFilterParsedDates(searchTerms, FieldType.dateUsShort)); expect(output).toBe(false); }); it('should return False when any of the 2 search term value is not a valid date', () => { - const searchTerms = ['12/01/93..12/60/93']; - const options = { dataKey: '', operator: 'RangeExclusive', cellValue: '12/05/93', fieldType: FieldType.dateUsShort, searchTerms } as FilterConditionOption; + const searchTerms = ['12/1/93..12/60/93']; + const options = { dataKey: '', operator: 'RangeExclusive', cellValue: '12/5/93', fieldType: FieldType.dateUsShort, searchTerms } as FilterConditionOption; const output = executeFilterConditionTest(options, getFilterParsedDates(searchTerms, FieldType.dateUsShort)); expect(output).toBe(false); }); diff --git a/packages/common/src/filter-conditions/__tests__/filterConditionProcesses.spec.ts b/packages/common/src/filter-conditions/__tests__/filterConditionProcesses.spec.ts index cd0e6d7b7..877afcc6e 100644 --- a/packages/common/src/filter-conditions/__tests__/filterConditionProcesses.spec.ts +++ b/packages/common/src/filter-conditions/__tests__/filterConditionProcesses.spec.ts @@ -1,4 +1,4 @@ -import moment from 'moment-mini'; +import moment from 'moment-tiny'; import { getParsedSearchTermsByFieldType } from '../filterConditionProcesses'; diff --git a/packages/common/src/filter-conditions/dateFilterCondition.ts b/packages/common/src/filter-conditions/dateFilterCondition.ts index 7a04a1299..d8dbf9009 100644 --- a/packages/common/src/filter-conditions/dateFilterCondition.ts +++ b/packages/common/src/filter-conditions/dateFilterCondition.ts @@ -1,4 +1,4 @@ -import moment from 'moment-mini'; +import moment from 'moment-tiny'; import { FieldType, OperatorType, type SearchTerm } from '../enums/index'; import type { FilterConditionOption } from '../interfaces/index'; @@ -11,6 +11,7 @@ import { testFilterCondition } from './filterUtilities'; export function executeDateFilterCondition(options: FilterConditionOption, parsedSearchDates: any[]): boolean { const filterSearchType = options && (options.filterSearchType || options.fieldType) || FieldType.dateIso; const FORMAT = mapMomentDateFormatWithFieldType(filterSearchType); + const SINGLE_FORMAT = Array.isArray(FORMAT) ? FORMAT[0] : FORMAT; const [searchDate1, searchDate2] = parsedSearchDates; // cell value in moment format @@ -23,7 +24,7 @@ export function executeDateFilterCondition(options: FilterConditionOption, parse // when comparing with Dates only (without time), we need to disregard the time portion, we can do so by setting our time to start at midnight // ref, see https://stackoverflow.com/a/19699447/1212166 - const dateCellTimestamp = FORMAT.toLowerCase().includes('h') ? dateCell.valueOf() : dateCell.clone().startOf('day').valueOf(); + const dateCellTimestamp = SINGLE_FORMAT.toLowerCase().includes('h') ? dateCell.valueOf() : dateCell.clone().startOf('day').valueOf(); // having 2 search dates, we assume that it's a date range filtering and we'll compare against both dates if (searchDate1 && searchDate2) { @@ -38,7 +39,7 @@ export function executeDateFilterCondition(options: FilterConditionOption, parse } // comparing against a single search date - const dateSearchTimestamp1 = FORMAT.toLowerCase().includes('h') ? searchDate1.valueOf() : searchDate1.clone().startOf('day').valueOf(); + const dateSearchTimestamp1 = SINGLE_FORMAT.toLowerCase().includes('h') ? searchDate1.valueOf() : searchDate1.clone().startOf('day').valueOf(); return testFilterCondition(options.operator || '==', dateCellTimestamp, dateSearchTimestamp1); } diff --git a/packages/common/src/filters/__tests__/compoundDateFilter.spec.ts b/packages/common/src/filters/__tests__/compoundDateFilter.spec.ts index 54095fb65..1e8cad5b6 100644 --- a/packages/common/src/filters/__tests__/compoundDateFilter.spec.ts +++ b/packages/common/src/filters/__tests__/compoundDateFilter.spec.ts @@ -285,7 +285,7 @@ describe('CompoundDateFilter', () => { }); it('should create the input filter with a default search terms when passed as a filter argument', () => { - filterArguments.searchTerms = ['2000-01-01T05:00:00.000+05:00']; + filterArguments.searchTerms = ['2000-01-01T05:00:00.000Z']; mockColumn.filter!.operator = '<='; mockColumn.type = FieldType.dateUtc; mockColumn.outputType = FieldType.dateUtc; @@ -295,14 +295,14 @@ describe('CompoundDateFilter', () => { const filterInputElm = divContainer.querySelector('.search-filter.filter-finish input.date-picker') as HTMLInputElement; filterInputElm.focus(); - filter.calendarInstance!.actions!.clickDay!(new MouseEvent('click'), { HTMLInputElement: filterInputElm, selectedDates: ['2000-01-01T05:00:00.000+05:00'], hide: jest.fn() } as unknown as VanillaCalendar); - filter.calendarInstance!.actions!.changeToInput!(new MouseEvent('click'), { HTMLInputElement: filterInputElm, selectedDates: ['2000-01-01T05:00:00.000+05:00'], hide: jest.fn() } as unknown as VanillaCalendar); + filter.calendarInstance!.actions!.clickDay!(new MouseEvent('click'), { HTMLInputElement: filterInputElm, selectedDates: ['2000-01-01T05:00:00.000Z'], hide: jest.fn() } as unknown as VanillaCalendar); + filter.calendarInstance!.actions!.changeToInput!(new MouseEvent('click'), { HTMLInputElement: filterInputElm, selectedDates: ['2000-01-01T05:00:00.000Z'], hide: jest.fn() } as unknown as VanillaCalendar); const filterFilledElms = divContainer.querySelectorAll('.form-group.search-filter.filter-finish.filled'); expect(filterFilledElms.length).toBe(1); - expect(filter.currentDateOrDates![0].toISOString()).toBe('2000-01-01T10:00:00.000Z'); - expect(filterInputElm.value).toBe('2000-01-01T10:00:00.000Z'); - expect(spyCallback).toHaveBeenCalledWith(expect.anything(), { columnDef: mockColumn, operator: '<=', searchTerms: ['2000-01-01T10:00:00.000Z'], shouldTriggerQuery: true }); + expect(filter.currentDateOrDates![0].toISOString()).toBe('2000-01-01T05:00:00.000Z'); + expect(filterInputElm.value).toBe('2000-01-01T05:00:00.000Z'); + expect(spyCallback).toHaveBeenCalledWith(expect.anything(), { columnDef: mockColumn, operator: '<=', searchTerms: ['2000-01-01T05:00:00.000Z'], shouldTriggerQuery: true }); }); it('should create the input filter with a default input dates when passed as a filter options', () => { @@ -377,7 +377,7 @@ describe('CompoundDateFilter', () => { it('should work with different locale when locale is changed', async () => { translateService.use('fr'); - filterArguments.searchTerms = ['2000-01-01T05:00:00.000+05:00']; + filterArguments.searchTerms = ['2000-01-01T05:00:00.000Z']; mockColumn.filter!.operator = '<='; mockColumn.type = FieldType.dateUtc; mockColumn.outputType = FieldType.dateUtc; @@ -393,14 +393,14 @@ describe('CompoundDateFilter', () => { filterInputElm.focus(); - filter.calendarInstance!.actions!.clickDay!(new MouseEvent('click'), { HTMLInputElement: filterInputElm, selectedDates: ['2000-01-01T05:00:00.000+05:00'], hide: jest.fn() } as unknown as VanillaCalendar); - filter.calendarInstance!.actions!.changeToInput!(new MouseEvent('click'), { HTMLInputElement: filterInputElm, selectedDates: ['2000-01-01T05:00:00.000+05:00'], hide: jest.fn() } as unknown as VanillaCalendar); + filter.calendarInstance!.actions!.clickDay!(new MouseEvent('click'), { HTMLInputElement: filterInputElm, selectedDates: ['2000-01-01T05:00:00.000Z'], hide: jest.fn() } as unknown as VanillaCalendar); + filter.calendarInstance!.actions!.changeToInput!(new MouseEvent('click'), { HTMLInputElement: filterInputElm, selectedDates: ['2000-01-01T05:00:00.000Z'], hide: jest.fn() } as unknown as VanillaCalendar); const filterFilledElms = divContainer.querySelectorAll('.form-group.search-filter.filter-finish.filled'); expect(filterFilledElms.length).toBe(1); - expect(filter.currentDateOrDates![0].toISOString()).toBe('2000-01-01T10:00:00.000Z'); - expect(filterInputElm.value).toBe('2000-01-01T10:00:00.000Z'); - expect(spyCallback).toHaveBeenCalledWith(expect.anything(), { columnDef: mockColumn, operator: '<=', searchTerms: ['2000-01-01T10:00:00.000Z'], shouldTriggerQuery: true }); + expect(filter.currentDateOrDates![0].toISOString()).toBe('2000-01-01T05:00:00.000Z'); + expect(filterInputElm.value).toBe('2000-01-01T05:00:00.000Z'); + expect(spyCallback).toHaveBeenCalledWith(expect.anything(), { columnDef: mockColumn, operator: '<=', searchTerms: ['2000-01-01T05:00:00.000Z'], shouldTriggerQuery: true }); expect(calendarElm).toBeTruthy(); expect(monthElm).toBeTruthy(); // expect(monthElm.textContent).toBe('janvier'); @@ -442,14 +442,14 @@ describe('CompoundDateFilter', () => { filter.init(filterArguments); const filterInputElm = divContainer.querySelector('.search-filter.filter-finish input.date-picker') as HTMLInputElement; - filterInputElm.value = '2001-01-02T16:02:02.000'; - filter.calendarInstance!.actions!.clickDay!(new MouseEvent('click'), { HTMLInputElement: filterInputElm, selectedDates: ['2001-01-02 16:02:02.000'], hide: jest.fn() } as unknown as VanillaCalendar); - filter.calendarInstance!.actions!.changeToInput!(new MouseEvent('click'), { HTMLInputElement: filterInputElm, selectedDates: ['2001-01-02 16:02:02.000'], hide: jest.fn() } as unknown as VanillaCalendar); + filterInputElm.value = '2001-01-02T16:02:00.000Z'; + filter.calendarInstance!.actions!.clickDay!(new MouseEvent('click'), { HTMLInputElement: filterInputElm, selectedDates: ['2001-01-02'], hide: jest.fn() } as unknown as VanillaCalendar); + filter.calendarInstance!.actions!.changeToInput!(new MouseEvent('click'), { HTMLInputElement: filterInputElm, selectedDates: ['2001-01-02'], selectedHours: 16, selectedMinutes: 2, hide: jest.fn() } as unknown as VanillaCalendar); const filterFilledElms = divContainer.querySelectorAll('.form-group.search-filter.filter-finish.filled'); expect(filterFilledElms.length).toBe(1); - // expect(filter.currentDateOrDates.toISOString()).toBe('2001-01-02T21:02:02.000Z'); - expect(filterInputElm.value).toBe('2001-01-02 04:02:02 pm'); + // expect(filter.currentDateOrDates.toISOString()).toBe('2001-01-02T21:02'); + expect(filterInputElm.value).toBe('2001-01-02 04:02:00 pm'); expect(spyCallback).toHaveBeenCalledWith(expect.anything(), { columnDef: mockColumn, operator: '>', searchTerms: ['2001-01-02'], shouldTriggerQuery: true }); @@ -458,7 +458,7 @@ describe('CompoundDateFilter', () => { it('should have a value with date & time in the picker when using no "outputType" which will default to UTC date', () => { mockColumn.type = FieldType.dateUtc; mockColumn.outputType = null as any; - filterArguments.searchTerms = ['2000-01-01T05:00:00.000+05:00']; + filterArguments.searchTerms = ['2000-01-01T05:00']; mockColumn.filter!.operator = '<='; const spyCallback = jest.spyOn(filterArguments, 'callback'); @@ -466,14 +466,14 @@ describe('CompoundDateFilter', () => { const filterInputElm = divContainer.querySelector('.search-filter.filter-finish input.date-picker') as HTMLInputElement; filterInputElm.focus(); - filter.calendarInstance!.actions!.clickDay!(new MouseEvent('click'), { HTMLInputElement: filterInputElm, selectedDates: ['2000-01-01T05:00:00.000+05:00'], hide: jest.fn() } as unknown as VanillaCalendar); - filter.calendarInstance!.actions!.changeToInput!(new MouseEvent('click'), { HTMLInputElement: filterInputElm, selectedDates: ['2000-01-01T05:00:00.000+05:00'], hide: jest.fn() } as unknown as VanillaCalendar); + filter.calendarInstance!.actions!.clickDay!(new MouseEvent('click'), { HTMLInputElement: filterInputElm, selectedDates: ['2000-01-01'], hide: jest.fn() } as unknown as VanillaCalendar); + filter.calendarInstance!.actions!.changeToInput!(new MouseEvent('click'), { HTMLInputElement: filterInputElm, selectedDates: ['2000-01-01'], hide: jest.fn() } as unknown as VanillaCalendar); const filterFilledElms = divContainer.querySelectorAll('.form-group.search-filter.filter-finish.filled'); expect(filterFilledElms.length).toBe(1); - expect(filter.currentDateOrDates![0].toISOString()).toBe('2000-01-01T10:00:00.000Z'); - expect(filterInputElm.value).toBe('2000-01-01T10:00:00.000Z'); - expect(spyCallback).toHaveBeenCalledWith(expect.anything(), { columnDef: mockColumn, operator: '<=', searchTerms: ['2000-01-01T10:00:00.000Z'], shouldTriggerQuery: true }); + expect(filter.currentDateOrDates![0].toISOString()).toBe('2000-01-01T05:00:00.000Z'); + expect(filterInputElm.value).toBe('2000-01-01T05:00:00.000Z'); + expect(spyCallback).toHaveBeenCalledWith(expect.anything(), { columnDef: mockColumn, operator: '<=', searchTerms: ['2000-01-01T05:00:00.000Z'], shouldTriggerQuery: true }); }); it('should have default English text with operator dropdown options related to dates', () => { diff --git a/packages/common/src/filters/dateFilter.ts b/packages/common/src/filters/dateFilter.ts index 9e6d5c961..b44a20127 100644 --- a/packages/common/src/filters/dateFilter.ts +++ b/packages/common/src/filters/dateFilter.ts @@ -1,8 +1,7 @@ import { BindingEventService } from '@slickgrid-universal/binding'; import { createDomElement, emptyElement, extend, } from '@slickgrid-universal/utils'; import { VanillaCalendar, type IOptions } from 'vanilla-calendar-picker'; -import * as moment_ from 'moment-mini'; -const moment = (moment_ as any)['default'] || moment_; +import moment, { type Moment } from 'moment-tiny'; import { FieldType, @@ -239,7 +238,10 @@ export class DateFilter implements Filter { const columnId = this.columnDef?.id ?? ''; const columnFieldType = this.columnFilter.type || this.columnDef.type || FieldType.dateIso; const outputFieldType = this.columnDef.outputType || this.columnFilter.type || this.columnDef.type || FieldType.dateUtc; - const outputFormat = mapMomentDateFormatWithFieldType(outputFieldType); + let outputFormat = mapMomentDateFormatWithFieldType(outputFieldType); + if (Array.isArray(outputFormat)) { + outputFormat = outputFormat[0]; + } const inputFieldType = this.columnFilter.type || this.columnDef.type || FieldType.dateIso; // add the time picker when format is UTC (Z) or has the 'h' (meaning hours) @@ -285,7 +287,7 @@ export class DateFilter implements Filter { }, changeToInput: (_e, self) => { if (self.HTMLInputElement) { - let outDates: Array = []; + let outDates: Array = []; let firstDate = ''; let lastDate = ''; // when using date range @@ -307,8 +309,8 @@ export class DateFilter implements Filter { if (this.hasTimePicker && firstDate) { const momentDate = moment(firstDate, pickerFormat); - momentDate.hours(self.selectedHours); - momentDate.minute(self.selectedMinutes); + momentDate.hours(+(self.selectedHours || 0)); + momentDate.minute(+(self.selectedMinutes || 0)); self.HTMLInputElement.value = formatDateByFieldType(momentDate, undefined, outputFieldType); outDates = [momentDate]; } @@ -321,7 +323,7 @@ export class DateFilter implements Filter { this._currentValue = this._currentDateStrings.join('..'); } } - this._currentDateOrDates = outDates.map(dateStr => dateStr instanceof moment ? (dateStr as moment_.Moment).toDate() : new Date(dateStr as string)); + this._currentDateOrDates = outDates.map(dateStr => dateStr instanceof moment ? (dateStr as Moment).toDate() : new Date(dateStr as string)); // when using the time picker, we can simulate a keyup event to avoid multiple backend request // since backend request are only executed after user start typing, changing the time should be treated the same way diff --git a/packages/common/src/formatters/__tests__/dateEuroShortFormatter.spec.ts b/packages/common/src/formatters/__tests__/dateEuroShortFormatter.spec.ts index 79a3a066b..c61cede1d 100644 --- a/packages/common/src/formatters/__tests__/dateEuroShortFormatter.spec.ts +++ b/packages/common/src/formatters/__tests__/dateEuroShortFormatter.spec.ts @@ -17,18 +17,18 @@ describe('the DateEuroShort Formatter', () => { it('should provide a dateIso formatted input and return a formatted date value without time when valid date value is provided', () => { const value = '2019-05-01 02:36:07'; const result = Formatters.dateEuroShort(0, 0, value, { type: 'dateIso' } as unknown as Column, {}, {} as any); - expect(result).toBe('1/5/19'); + expect(result).toBe('01/05/19'); }); it('should return a formatted date value in the morning when valid date value is provided', () => { const value = new Date('2019-05-01T02:36:07'); const result = Formatters.dateEuroShort(0, 0, value, {} as Column, {}, {} as any); - expect(result).toBe('1/5/19'); + expect(result).toBe('01/05/19'); }); it('should return a formatted date value in the afternoon when valid date value is provided', () => { const value = new Date('2019-05-01T20:36:07'); const result = Formatters.dateEuroShort(0, 0, value, {} as Column, {}, {} as any); - expect(result).toBe('1/5/19'); + expect(result).toBe('01/05/19'); }); }); diff --git a/packages/common/src/formatters/__tests__/dateTimeEuroShortAM_PMFormatter.spec.ts b/packages/common/src/formatters/__tests__/dateTimeEuroShortAM_PMFormatter.spec.ts index a0048e9fe..37cf2d41d 100644 --- a/packages/common/src/formatters/__tests__/dateTimeEuroShortAM_PMFormatter.spec.ts +++ b/packages/common/src/formatters/__tests__/dateTimeEuroShortAM_PMFormatter.spec.ts @@ -17,18 +17,18 @@ describe('the DateTimeEuroShortAM_PM Formatter', () => { it('should provide a dateIso formatted input and return a formatted date value without time when valid date value is provided', () => { const value = '2019-05-01 02:36:07'; const result = Formatters.dateTimeEuroShortAM_PM(0, 0, value, { type: 'dateIso' } as unknown as Column, {}, {} as any); - expect(result).toBe('1/5/19 2:36:7 AM'); + expect(result).toBe('01/05/19 2:36:7 AM'); }); it('should return a formatted date value in the morning when valid date value is provided', () => { const value = new Date('2019-05-01T02:36:07'); const result = Formatters.dateTimeEuroShortAM_PM(0, 0, value, {} as Column, {}, {} as any); - expect(result).toBe('1/5/19 2:36:7 AM'); + expect(result).toBe('01/05/19 2:36:7 AM'); }); it('should return a formatted date value in the afternoon when valid date value is provided', () => { const value = new Date('2019-05-01T20:36:07'); const result = Formatters.dateTimeEuroShortAM_PM(0, 0, value, {} as Column, {}, {} as any); - expect(result).toBe('1/5/19 8:36:7 PM'); + expect(result).toBe('01/05/19 8:36:7 PM'); }); }); diff --git a/packages/common/src/formatters/__tests__/dateTimeEuroShortAmPmFormatter.spec.ts b/packages/common/src/formatters/__tests__/dateTimeEuroShortAmPmFormatter.spec.ts index 79fe87bf8..2edfdee9f 100644 --- a/packages/common/src/formatters/__tests__/dateTimeEuroShortAmPmFormatter.spec.ts +++ b/packages/common/src/formatters/__tests__/dateTimeEuroShortAmPmFormatter.spec.ts @@ -17,18 +17,18 @@ describe('the DateTimeEuroShortAmPm Formatter', () => { it('should provide a dateIso formatted input and return a formatted date value without time when valid date value is provided', () => { const value = '2019-05-01 02:36:07'; const result = Formatters.dateTimeEuroShortAmPm(0, 0, value, { type: 'dateIso' } as unknown as Column, {}, {} as any); - expect(result).toBe('1/5/19 2:36:7 am'); + expect(result).toBe('01/05/19 2:36:7 am'); }); it('should return a formatted date value in the morning when valid date value is provided', () => { const value = new Date('2019-05-01T02:36:07'); const result = Formatters.dateTimeEuroShortAmPm(0, 0, value, {} as Column, {}, {} as any); - expect(result).toBe('1/5/19 2:36:7 am'); + expect(result).toBe('01/05/19 2:36:7 am'); }); it('should return a formatted date value in the afternoon when valid date value is provided', () => { const value = new Date('2019-05-01T20:36:07'); const result = Formatters.dateTimeEuroShortAmPm(0, 0, value, {} as Column, {}, {} as any); - expect(result).toBe('1/5/19 8:36:7 pm'); + expect(result).toBe('01/05/19 8:36:7 pm'); }); }); diff --git a/packages/common/src/formatters/__tests__/dateTimeEuroShortFormatter.spec.ts b/packages/common/src/formatters/__tests__/dateTimeEuroShortFormatter.spec.ts index 5fa2d03d4..68595f5f0 100644 --- a/packages/common/src/formatters/__tests__/dateTimeEuroShortFormatter.spec.ts +++ b/packages/common/src/formatters/__tests__/dateTimeEuroShortFormatter.spec.ts @@ -17,18 +17,18 @@ describe('the DateTimeEuroShort Formatter', () => { it('should provide a dateIso formatted input and return a formatted date value without time when valid date value is provided', () => { const value = '2019-05-01 02:36:07'; const result = Formatters.dateTimeEuroShort(0, 0, value, { type: 'dateIso' } as unknown as Column, {}, {} as any); - expect(result).toBe('1/5/19 2:36:7'); + expect(result).toBe('01/05/19 2:36:7'); }); it('should return a formatted date value in the morning when valid date value is provided', () => { const value = new Date('2019-05-01T02:36:07'); const result = Formatters.dateTimeEuroShort(0, 0, value, {} as Column, {}, {} as any); - expect(result).toBe('1/5/19 2:36:7'); + expect(result).toBe('01/05/19 2:36:7'); }); it('should return a formatted date value in the afternoon when valid date value is provided', () => { const value = new Date('2019-05-01T20:36:07'); const result = Formatters.dateTimeEuroShort(0, 0, value, {} as Column, {}, {} as any); - expect(result).toBe('1/5/19 20:36:7'); + expect(result).toBe('01/05/19 20:36:7'); }); }); diff --git a/packages/common/src/formatters/__tests__/dateTimeUsShortAM_PMFormatter.spec.ts b/packages/common/src/formatters/__tests__/dateTimeUsShortAM_PMFormatter.spec.ts index 58363f1f4..b665b3753 100644 --- a/packages/common/src/formatters/__tests__/dateTimeUsShortAM_PMFormatter.spec.ts +++ b/packages/common/src/formatters/__tests__/dateTimeUsShortAM_PMFormatter.spec.ts @@ -17,18 +17,18 @@ describe('the DateTimeUsShortAM_PM Formatter', () => { it('should provide a dateIso formatted input and return a formatted date value without time when valid date value is provided', () => { const value = '2019-05-01 02:36:07'; const result = Formatters.dateTimeUsShortAM_PM(0, 0, value, { type: 'dateIso' } as unknown as Column, {}, {} as any); - expect(result).toBe('5/1/19 2:36:7 AM'); + expect(result).toBe('05/01/19 2:36:7 AM'); }); it('should return a formatted date value in the morning when valid date value is provided', () => { const value = new Date('2019-05-01T02:36:07'); const result = Formatters.dateTimeUsShortAM_PM(0, 0, value, {} as Column, {}, {} as any); - expect(result).toBe('5/1/19 2:36:7 AM'); + expect(result).toBe('05/01/19 2:36:7 AM'); }); it('should return a formatted date value in the afternoon when valid date value is provided', () => { const value = new Date('2019-05-01T20:36:07'); const result = Formatters.dateTimeUsShortAM_PM(0, 0, value, {} as Column, {}, {} as any); - expect(result).toBe('5/1/19 8:36:7 PM'); + expect(result).toBe('05/01/19 8:36:7 PM'); }); }); diff --git a/packages/common/src/formatters/__tests__/dateTimeUsShortAmPmFormatter.spec.ts b/packages/common/src/formatters/__tests__/dateTimeUsShortAmPmFormatter.spec.ts index 7ffcb961a..d2b86931d 100644 --- a/packages/common/src/formatters/__tests__/dateTimeUsShortAmPmFormatter.spec.ts +++ b/packages/common/src/formatters/__tests__/dateTimeUsShortAmPmFormatter.spec.ts @@ -17,18 +17,18 @@ describe('the DateTimeUsShortAmPm Formatter', () => { it('should provide a dateIso formatted input and return a formatted date value without time when valid date value is provided', () => { const value = '2019-05-01 02:36:07'; const result = Formatters.dateTimeUsShortAmPm(0, 0, value, { type: 'dateIso' } as unknown as Column, {}, {} as any); - expect(result).toBe('5/1/19 2:36:7 am'); + expect(result).toBe('05/01/19 2:36:7 am'); }); it('should return a formatted date value in the morning when valid date value is provided', () => { const value = new Date('2019-05-01T02:36:07'); const result = Formatters.dateTimeUsShortAmPm(0, 0, value, {} as Column, {}, {} as any); - expect(result).toBe('5/1/19 2:36:7 am'); + expect(result).toBe('05/01/19 2:36:7 am'); }); it('should return a formatted date value in the afternoon when valid date value is provided', () => { const value = new Date('2019-05-01T20:36:07'); const result = Formatters.dateTimeUsShortAmPm(0, 0, value, {} as Column, {}, {} as any); - expect(result).toBe('5/1/19 8:36:7 pm'); + expect(result).toBe('05/01/19 8:36:7 pm'); }); }); diff --git a/packages/common/src/formatters/__tests__/dateTimeUsShortFormatter.spec.ts b/packages/common/src/formatters/__tests__/dateTimeUsShortFormatter.spec.ts index 0ca980ad7..99001ff1c 100644 --- a/packages/common/src/formatters/__tests__/dateTimeUsShortFormatter.spec.ts +++ b/packages/common/src/formatters/__tests__/dateTimeUsShortFormatter.spec.ts @@ -17,18 +17,18 @@ describe('the DateTimeUsShort Formatter', () => { it('should provide a dateIso formatted input and return a formatted date value without time when valid date value is provided', () => { const value = '2019-05-01 02:36:07'; const result = Formatters.dateTimeUsShort(0, 0, value, { type: 'dateIso' } as unknown as Column, {}, {} as any); - expect(result).toBe('5/1/19 2:36:7'); + expect(result).toBe('05/01/19 2:36:7'); }); it('should return a formatted date value in the morning when valid date value is provided', () => { const value = new Date('2019-05-01T02:36:07'); const result = Formatters.dateTimeUsShort(0, 0, value, {} as Column, {}, {} as any); - expect(result).toBe('5/1/19 2:36:7'); + expect(result).toBe('05/01/19 2:36:7'); }); it('should return a formatted date value in the afternoon when valid date value is provided', () => { const value = new Date('2019-05-01T20:36:07'); const result = Formatters.dateTimeUsShort(0, 0, value, {} as Column, {}, {} as any); - expect(result).toBe('5/1/19 20:36:7'); + expect(result).toBe('05/01/19 20:36:7'); }); }); diff --git a/packages/common/src/formatters/__tests__/dateUsShortFormatter.spec.ts b/packages/common/src/formatters/__tests__/dateUsShortFormatter.spec.ts index eeba6e7f1..c85b45a32 100644 --- a/packages/common/src/formatters/__tests__/dateUsShortFormatter.spec.ts +++ b/packages/common/src/formatters/__tests__/dateUsShortFormatter.spec.ts @@ -17,18 +17,18 @@ describe('the DateUsShort Formatter', () => { it('should provide a dateIso formatted input and return a formatted date value without time when valid date value is provided', () => { const value = '2019-05-01 02:36:07'; const result = Formatters.dateUsShort(0, 0, value, { type: 'dateIso' } as unknown as Column, {}, {} as any); - expect(result).toBe('5/1/19'); + expect(result).toBe('05/01/19'); }); it('should return a formatted date value in the morning when valid date value is provided', () => { const value = new Date('2019-05-01T02:36:07'); const result = Formatters.dateUsShort(0, 0, value, {} as Column, {}, {} as any); - expect(result).toBe('5/1/19'); + expect(result).toBe('05/01/19'); }); it('should return a formatted date value in the afternoon when valid date value is provided', () => { const value = new Date('2019-05-01T20:36:07'); const result = Formatters.dateUsShort(0, 0, value, {} as Column, {}, {} as any); - expect(result).toBe('5/1/19'); + expect(result).toBe('05/01/19'); }); }); diff --git a/packages/common/src/formatters/formatterUtilities.ts b/packages/common/src/formatters/formatterUtilities.ts index ac83b11c9..116168c28 100644 --- a/packages/common/src/formatters/formatterUtilities.ts +++ b/packages/common/src/formatters/formatterUtilities.ts @@ -1,5 +1,5 @@ import { getHtmlStringOutput, isPrimitiveOrHTML, stripTags } from '@slickgrid-universal/utils'; -import moment from 'moment-mini'; +import moment from 'moment-tiny'; import { FieldType } from '../enums/fieldType.enum'; import type { Column, ExcelExportOption, Formatter, FormatterResultWithHtml, FormatterResultWithText, GridOption, TextExportOption } from '../interfaces/index'; @@ -96,7 +96,10 @@ export function getValueFromParamsOrFormatterOptions(optionName: string, columnD /** From a FieldType, return the associated date Formatter */ export function getAssociatedDateFormatter(fieldType: typeof FieldType[keyof typeof FieldType], defaultSeparator: string): Formatter { - const defaultDateFormat = mapMomentDateFormatWithFieldType(fieldType); + let defaultDateFormat = mapMomentDateFormatWithFieldType(fieldType); + if (Array.isArray(defaultDateFormat)) { + defaultDateFormat = defaultDateFormat[0]; + } return (_row: number, _cell: number, value: any, columnDef: Column, _dataContext: any, grid: SlickGrid) => { const gridOptions = ((grid && typeof grid.getOptions === 'function') ? grid.getOptions() : {}) as GridOption; diff --git a/packages/common/src/services/__tests__/utilities.spec.ts b/packages/common/src/services/__tests__/utilities.spec.ts index b30aefaa2..8b52fdb5e 100644 --- a/packages/common/src/services/__tests__/utilities.spec.ts +++ b/packages/common/src/services/__tests__/utilities.spec.ts @@ -738,7 +738,7 @@ describe('Service/Utilies', () => { it('should return a moment.js dateEuroShort format', () => { const output = mapMomentDateFormatWithFieldType(FieldType.dateEuroShort); - expect(output).toBe('D/M/YY'); + expect(output).toEqual(['DD/MM/YY', 'D/M/YY']); }); it('should return a moment.js dateTimeEuro format', () => { @@ -748,7 +748,7 @@ describe('Service/Utilies', () => { it('should return a moment.js dateTimeShortEuro format', () => { const output = mapMomentDateFormatWithFieldType(FieldType.dateTimeShortEuro); - expect(output).toBe('DD/MM/YYYY HH:mm'); + expect(output).toEqual(['DD/MM/YYYY HH:mm', 'D/M/YYYY HH:mm']); }); it('should return a moment.js dateTimeEuroAmPm format', () => { @@ -763,12 +763,12 @@ describe('Service/Utilies', () => { it('should return a moment.js dateTimeEuroShort format', () => { const output = mapMomentDateFormatWithFieldType(FieldType.dateTimeEuroShort); - expect(output).toBe('D/M/YY H:m:s'); + expect(output).toEqual(['DD/MM/YY H:m:s', 'D/M/YY H:m:s']); }); it('should return a moment.js dateTimeEuroShortAmPm format', () => { const output = mapMomentDateFormatWithFieldType(FieldType.dateTimeEuroShortAmPm); - expect(output).toBe('D/M/YY h:m:s a'); + expect(output).toEqual(['DD/MM/YY h:m:s a', 'D/M/YY h:m:s a']); }); it('should return a moment.js dateUs format', () => { @@ -778,7 +778,7 @@ describe('Service/Utilies', () => { it('should return a moment.js dateUsShort format', () => { const output = mapMomentDateFormatWithFieldType(FieldType.dateUsShort); - expect(output).toBe('M/D/YY'); + expect(output).toEqual(['MM/DD/YY', 'M/D/YY']); }); it('should return a moment.js dateTimeUs format', () => { @@ -788,7 +788,7 @@ describe('Service/Utilies', () => { it('should return a moment.js dateTimeShortUs format', () => { const output = mapMomentDateFormatWithFieldType(FieldType.dateTimeShortUs); - expect(output).toBe('MM/DD/YYYY HH:mm'); + expect(output).toEqual(['MM/DD/YYYY HH:mm', 'M/D/YYYY HH:mm']); }); it('should return a moment.js dateTimeUsAmPm format', () => { @@ -803,12 +803,12 @@ describe('Service/Utilies', () => { it('should return a moment.js dateTimeUsShort format', () => { const output = mapMomentDateFormatWithFieldType(FieldType.dateTimeUsShort); - expect(output).toBe('M/D/YY H:m:s'); + expect(output).toEqual(['MM/DD/YY H:m:s', 'M/D/YY H:m:s']); }); it('should return a moment.js dateTimeUsShortAmPm format', () => { const output = mapMomentDateFormatWithFieldType(FieldType.dateTimeUsShortAmPm); - expect(output).toBe('M/D/YY h:m:s a'); + expect(output).toEqual(['MM/DD/YY h:m:s a', 'M/D/YY h:m:s a']); }); it('should return a moment.js dateUtc format', () => { diff --git a/packages/common/src/services/utilities.ts b/packages/common/src/services/utilities.ts index 5794e82c8..32feaf5d8 100644 --- a/packages/common/src/services/utilities.ts +++ b/packages/common/src/services/utilities.ts @@ -1,7 +1,6 @@ import type { EventSubscription } from '@slickgrid-universal/event-pub-sub'; import { flatten } from 'un-flatten-tree'; -import * as moment_ from 'moment-mini'; -const moment = (moment_ as any)['default'] || moment_; +import moment, { type Moment } from 'moment-tiny'; import { Constants } from '../constants'; import { FieldType, type OperatorString, OperatorType } from '../enums/index'; @@ -400,16 +399,16 @@ export function isColumnDateType(fieldType: typeof FieldType[keyof typeof FieldT } } -export function formatDateByFieldType(inputDate: Date | string | typeof moment, inputFieldType: typeof FieldType[keyof typeof FieldType] | undefined, outputFieldType: typeof FieldType[keyof typeof FieldType]): string { +export function formatDateByFieldType(inputDate: Date | string | Moment, inputFieldType: typeof FieldType[keyof typeof FieldType] | undefined, outputFieldType: typeof FieldType[keyof typeof FieldType]): string { const inputFormat = inputFieldType ? mapMomentDateFormatWithFieldType(inputFieldType) : undefined; const outputFormat = mapMomentDateFormatWithFieldType(outputFieldType); - const momentDate = inputDate instanceof moment ? inputDate : moment(inputDate, inputFormat); + const momentDate = (inputDate instanceof moment ? inputDate : moment(inputDate, inputFormat)) as Moment; if (momentDate.isValid() && inputDate !== undefined) { if (outputFieldType === FieldType.dateUtc) { return momentDate.toISOString(); } - return momentDate.format(outputFormat); + return momentDate.format(Array.isArray(outputFormat) ? outputFormat[0] : outputFormat); } return ''; } @@ -419,8 +418,8 @@ export function formatDateByFieldType(inputDate: Date | string | typeof moment, * refer to moment.js for the format standard used: https://momentjs.com/docs/#/parsing/string-format/ * @param fieldType */ -export function mapMomentDateFormatWithFieldType(fieldType: typeof FieldType[keyof typeof FieldType]): string { - let map: string; +export function mapMomentDateFormatWithFieldType(fieldType: typeof FieldType[keyof typeof FieldType]): string | string[] { + let map: string | string[]; switch (fieldType) { case FieldType.dateTime: case FieldType.dateTimeIso: @@ -440,13 +439,13 @@ export function mapMomentDateFormatWithFieldType(fieldType: typeof FieldType[key map = 'DD/MM/YYYY'; break; case FieldType.dateEuroShort: - map = 'D/M/YY'; + map = ['DD/MM/YY', 'D/M/YY']; break; case FieldType.dateTimeEuro: map = 'DD/MM/YYYY HH:mm:ss'; break; case FieldType.dateTimeShortEuro: - map = 'DD/MM/YYYY HH:mm'; + map = ['DD/MM/YYYY HH:mm', 'D/M/YYYY HH:mm']; break; case FieldType.dateTimeEuroAmPm: map = 'DD/MM/YYYY hh:mm:ss a'; @@ -455,20 +454,20 @@ export function mapMomentDateFormatWithFieldType(fieldType: typeof FieldType[key map = 'DD/MM/YYYY hh:mm:ss A'; break; case FieldType.dateTimeEuroShort: - map = 'D/M/YY H:m:s'; + map = ['DD/MM/YY H:m:s', 'D/M/YY H:m:s']; break; case FieldType.dateTimeEuroShortAmPm: - map = 'D/M/YY h:m:s a'; + map = ['DD/MM/YY h:m:s a', 'D/M/YY h:m:s a']; break; case FieldType.dateTimeEuroShortAM_PM: - map = 'D/M/YY h:m:s A'; + map = ['DD/MM/YY h:m:s A', 'D/M/YY h:m:s A']; break; // all US Formats (month/date/year) case FieldType.dateUs: map = 'MM/DD/YYYY'; break; case FieldType.dateUsShort: - map = 'M/D/YY'; + map = ['MM/DD/YY', 'M/D/YY']; break; case FieldType.dateTimeUs: map = 'MM/DD/YYYY HH:mm:ss'; @@ -480,16 +479,16 @@ export function mapMomentDateFormatWithFieldType(fieldType: typeof FieldType[key map = 'MM/DD/YYYY hh:mm:ss A'; break; case FieldType.dateTimeUsShort: - map = 'M/D/YY H:m:s'; + map = ['MM/DD/YY H:m:s', 'M/D/YY H:m:s']; break; case FieldType.dateTimeUsShortAmPm: - map = 'M/D/YY h:m:s a'; + map = ['MM/DD/YY h:m:s a', 'M/D/YY h:m:s a']; break; case FieldType.dateTimeUsShortAM_PM: - map = 'M/D/YY h:m:s A'; + map = ['MM/DD/YY h:m:s A', 'M/D/YY h:m:s A']; break; case FieldType.dateTimeShortUs: - map = 'MM/DD/YYYY HH:mm'; + map = ['MM/DD/YYYY HH:mm', 'M/D/YYYY HH:mm']; break; case FieldType.dateUtc: map = 'YYYY-MM-DDTHH:mm:ss.SSSZ'; diff --git a/packages/common/src/sortComparers/__tests__/dateEuroShortSortComparer.spec.ts b/packages/common/src/sortComparers/__tests__/dateEuroShortSortComparer.spec.ts index 918e21bce..55eea91ee 100644 --- a/packages/common/src/sortComparers/__tests__/dateEuroShortSortComparer.spec.ts +++ b/packages/common/src/sortComparers/__tests__/dateEuroShortSortComparer.spec.ts @@ -4,30 +4,30 @@ import { FieldType, SortDirectionNumber } from '../../enums/index'; describe('the Date Euro Short Sorter', () => { it('should return an array of dates sorted ascending when only valid dates are provided', () => { const direction = SortDirectionNumber.asc; - const inputArray = ['8/8/98', '8/10/98', '8/8/98', '01/01/18', '14/12/98']; + const inputArray = ['8/8/98', '8/10/98', '8/8/98', '1/1/18', '14/12/98']; inputArray.sort((value1, value2) => sortByFieldType(FieldType.dateEuroShort, value1, value2, direction)); - expect(inputArray).toEqual(['8/8/98', '8/8/98', '8/10/98', '14/12/98', '01/01/18']); + expect(inputArray).toEqual(['8/8/98', '8/8/98', '8/10/98', '14/12/98', '1/1/18']); }); it('should return an array of dates sorted descending when only valid dates are provided', () => { const direction = SortDirectionNumber.desc; - const inputArray = ['8/8/98', '8/10/98', null, '8/8/98', '01/01/18', '14/12/98']; + const inputArray = ['8/8/98', '8/10/98', null, '8/8/98', '1/1/18', '14/12/98']; inputArray.sort((value1, value2) => sortByFieldType(FieldType.dateEuroShort, value1, value2, direction)); - expect(inputArray).toEqual(['01/01/18', '14/12/98', '8/10/98', '8/8/98', '8/8/98', null]); + expect(inputArray).toEqual(['1/1/18', '14/12/98', '8/10/98', '8/8/98', '8/8/98', null]); }); it(`should return an array with unsorted characters showing at the beginning then comes numbers sorted ascending when digits and chars are provided`, () => { const direction = SortDirectionNumber.asc; - const inputArray = ['8/10/98', 'y', '8/8/98', '01/01/18', '14/12/98']; + const inputArray = ['8/10/98', 'y', '8/8/98', '1/1/18', '14/12/98']; inputArray.sort((value1, value2) => sortByFieldType(FieldType.dateEuroShort, value1, value2, direction)); - expect(inputArray).toEqual(['y', '8/8/98', '8/10/98', '14/12/98', '01/01/18']); + expect(inputArray).toEqual(['y', '8/8/98', '8/10/98', '14/12/98', '1/1/18']); }); it(`should return an array with dates sorted descending showing at the beginning then characters`, () => { const direction = SortDirectionNumber.desc; - const inputArray = ['8/10/98', null, '8/8/98', '01/01/18', '14/12/98']; + const inputArray = ['8/10/98', null, '8/8/98', '1/1/18', '14/12/98']; inputArray.sort((value1, value2) => sortByFieldType(FieldType.dateEuroShort, value1, value2, direction)); - expect(inputArray).toEqual(['01/01/18', '14/12/98', '8/10/98', '8/8/98', null]); + expect(inputArray).toEqual(['1/1/18', '14/12/98', '8/10/98', '8/8/98', null]); }); }); diff --git a/packages/common/src/sortComparers/__tests__/dateUsShortSortComparer.spec.ts b/packages/common/src/sortComparers/__tests__/dateUsShortSortComparer.spec.ts index 420474326..64a00bf77 100644 --- a/packages/common/src/sortComparers/__tests__/dateUsShortSortComparer.spec.ts +++ b/packages/common/src/sortComparers/__tests__/dateUsShortSortComparer.spec.ts @@ -4,30 +4,30 @@ import { FieldType, SortDirectionNumber } from '../../enums/index'; describe('the Date US Short Sorter', () => { it('should return an array of US dates sorted ascending when only valid dates are provided', () => { const direction = SortDirectionNumber.asc; - const inputArray = ['8/8/98', '10/8/98', '8/8/98', '01/01/18', '12/14/98']; + const inputArray = ['8/8/98', '10/8/98', '8/8/98', '1/1/18', '12/14/98']; inputArray.sort((value1, value2) => sortByFieldType(FieldType.dateUsShort, value1, value2, direction)); - expect(inputArray).toEqual(['8/8/98', '8/8/98', '10/8/98', '12/14/98', '01/01/18']); + expect(inputArray).toEqual(['8/8/98', '8/8/98', '10/8/98', '12/14/98', '1/1/18']); }); it('should return an array of US dates sorted descending when only valid dates are provided', () => { const direction = SortDirectionNumber.desc; - const inputArray = ['8/8/98', '10/8/98', null, '8/8/98', '01/01/18', '12/14/98']; + const inputArray = ['8/8/98', '10/8/98', null, '8/8/98', '1/1/18', '12/14/98']; inputArray.sort((value1, value2) => sortByFieldType(FieldType.dateUsShort, value1, value2, direction)); - expect(inputArray).toEqual(['01/01/18', '12/14/98', '10/8/98', '8/8/98', '8/8/98', null]); + expect(inputArray).toEqual(['1/1/18', '12/14/98', '10/8/98', '8/8/98', '8/8/98', null]); }); it(`should return an array with unsorted characters showing at the beginning then comes numbers sorted ascending when digits and chars are provided`, () => { const direction = SortDirectionNumber.asc; - const inputArray = ['10/8/98', 'y', '8/8/98', '01/01/18', '12/14/98']; + const inputArray = ['10/8/98', 'y', '8/8/98', '1/1/18', '12/14/98']; inputArray.sort((value1, value2) => sortByFieldType(FieldType.dateUsShort, value1, value2, direction)); - expect(inputArray).toEqual(['y', '8/8/98', '10/8/98', '12/14/98', '01/01/18']); + expect(inputArray).toEqual(['y', '8/8/98', '10/8/98', '12/14/98', '1/1/18']); }); it(`should return an array with dates sorted descending showing at the beginning then characters`, () => { const direction = SortDirectionNumber.desc; - const inputArray = ['10/8/98', null, '8/8/98', '01/01/18', '12/14/98']; + const inputArray = ['10/8/98', null, '8/8/98', '1/1/18', '12/14/98']; inputArray.sort((value1, value2) => sortByFieldType(FieldType.dateUsShort, value1, value2, direction)); - expect(inputArray).toEqual(['01/01/18', '12/14/98', '10/8/98', '8/8/98', null]); + expect(inputArray).toEqual(['1/1/18', '12/14/98', '10/8/98', '8/8/98', null]); }); }); diff --git a/packages/common/src/sortComparers/dateUtilities.ts b/packages/common/src/sortComparers/dateUtilities.ts index 7615557a6..2ebcffa98 100644 --- a/packages/common/src/sortComparers/dateUtilities.ts +++ b/packages/common/src/sortComparers/dateUtilities.ts @@ -1,25 +1,24 @@ -import * as moment_ from 'moment-mini'; -const moment = (moment_ as any)['default'] || moment_; +import moment, { type Moment, type MomentBuiltinFormat } from 'moment-tiny'; import { FieldType } from '../enums/fieldType.enum'; import type { SortComparer } from '../interfaces/index'; import { mapMomentDateFormatWithFieldType } from '../services/utilities'; -export function compareDates(value1: any, value2: any, sortDirection: number, format: string | moment_.MomentBuiltinFormat, strict?: boolean) { +export function compareDates(value1: any, value2: any, sortDirection: number, format?: string | string[] | MomentBuiltinFormat, strict?: boolean) { let diff = 0; if (value1 === value2) { diff = 0; } else { // use moment to validate the date - let date1: moment_.Moment | Date = moment(value1, format, strict); - let date2: moment_.Moment | Date = moment(value2, format, strict); + let date1: Moment | Date = moment(value1, format, strict); + let date2: Moment | Date = moment(value2, format, strict); // when moment date is invalid, we'll create a temporary old Date - if (!(date1 as moment_.Moment).isValid()) { + if (!(date1 as Moment).isValid()) { date1 = new Date(1001, 1, 1); } - if (!(date2 as moment_.Moment).isValid()) { + if (!(date2 as Moment).isValid()) { date2 = new Date(1001, 1, 1); } @@ -32,10 +31,10 @@ export function compareDates(value1: any, value2: any, sortDirection: number, fo /** From a FieldType, return the associated Date SortComparer */ export function getAssociatedDateSortComparer(fieldType: typeof FieldType[keyof typeof FieldType]): SortComparer { - const FORMAT = (fieldType === FieldType.date) ? moment.ISO_8601 : mapMomentDateFormatWithFieldType(fieldType); + const FORMAT = (fieldType === FieldType.date) ? undefined : mapMomentDateFormatWithFieldType(fieldType); return ((value1: any, value2: any, sortDirection: number) => { - if (FORMAT === moment.ISO_8601) { + if (FORMAT === undefined) { return compareDates(value1, value2, sortDirection, FORMAT, false) as number; } return compareDates(value1, value2, sortDirection, FORMAT, true) as number; diff --git a/packages/custom-footer-component/package.json b/packages/custom-footer-component/package.json index 4dbfe32e6..b227145e3 100644 --- a/packages/custom-footer-component/package.json +++ b/packages/custom-footer-component/package.json @@ -51,7 +51,7 @@ "dependencies": { "@slickgrid-universal/binding": "workspace:~", "@slickgrid-universal/common": "workspace:~", - "moment-mini": "^2.29.4" + "moment-tiny": "^2.30.3" }, "devDependencies": { "@slickgrid-universal/event-pub-sub": "workspace:~" diff --git a/packages/custom-footer-component/src/slick-footer.component.ts b/packages/custom-footer-component/src/slick-footer.component.ts index b1b0248b0..d485ca9e2 100644 --- a/packages/custom-footer-component/src/slick-footer.component.ts +++ b/packages/custom-footer-component/src/slick-footer.component.ts @@ -1,4 +1,4 @@ -import moment from 'moment-mini'; +import moment from 'moment-tiny'; import type { CustomFooterOption, GridOption, diff --git a/packages/excel-export/package.json b/packages/excel-export/package.json index 7fe307073..5385e9083 100644 --- a/packages/excel-export/package.json +++ b/packages/excel-export/package.json @@ -52,7 +52,7 @@ "@slickgrid-universal/common": "workspace:~", "@slickgrid-universal/utils": "workspace:~", "excel-builder-vanilla": "^3.0.1", - "moment-mini": "^2.29.4" + "moment-tiny": "^2.30.3" }, "devDependencies": { "@slickgrid-universal/event-pub-sub": "workspace:~" diff --git a/packages/graphql/package.json b/packages/graphql/package.json index 24911c888..84d705843 100644 --- a/packages/graphql/package.json +++ b/packages/graphql/package.json @@ -53,7 +53,7 @@ "@slickgrid-universal/utils": "workspace:~" }, "devDependencies": { - "moment-mini": "^2.29.4" + "moment-tiny": "^2.30.3" }, "funding": { "type": "ko_fi", diff --git a/packages/graphql/src/services/__tests__/graphqlQueryBuilder.spec.ts b/packages/graphql/src/services/__tests__/graphqlQueryBuilder.spec.ts index b7b999e79..96c5cbf65 100644 --- a/packages/graphql/src/services/__tests__/graphqlQueryBuilder.spec.ts +++ b/packages/graphql/src/services/__tests__/graphqlQueryBuilder.spec.ts @@ -1,4 +1,4 @@ -import moment from 'moment-mini'; +import moment from 'moment-tiny'; import GraphqlQueryBuilder from '../graphqlQueryBuilder'; function removeSpaces(textS) { diff --git a/packages/vanilla-bundle/src/index.ts b/packages/vanilla-bundle/src/index.ts index a73b3d9bc..dde03050d 100644 --- a/packages/vanilla-bundle/src/index.ts +++ b/packages/vanilla-bundle/src/index.ts @@ -5,7 +5,7 @@ import { SlickEmptyWarningComponent } from '@slickgrid-universal/empty-warning-c import { SlickPaginationComponent } from '@slickgrid-universal/pagination-component'; import { SlickVanillaGridBundle } from './components/slick-vanilla-grid-bundle'; -const Slicker = { +const Slicker: any = { GridBundle: SlickVanillaGridBundle, Aggregators, BindingService, diff --git a/packages/vanilla-force-bundle/src/index.ts b/packages/vanilla-force-bundle/src/index.ts index d49ed1c04..c37c76b0d 100644 --- a/packages/vanilla-force-bundle/src/index.ts +++ b/packages/vanilla-force-bundle/src/index.ts @@ -6,7 +6,7 @@ import { SlickEmptyWarningComponent } from '@slickgrid-universal/empty-warning-c import { SlickPaginationComponent } from '@slickgrid-universal/pagination-component'; import { VanillaForceGridBundle } from './vanilla-force-bundle'; -const Slicker = { +const Slicker: any = { GridBundle: VanillaForceGridBundle, Aggregators, BindingService, diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index a438321bf..ccbed8dee 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -86,9 +86,9 @@ importers: jsdom-global: specifier: ^3.0.2 version: 3.0.2(jsdom@24.0.0) - moment-mini: - specifier: ^2.29.4 - version: 2.29.4 + moment-tiny: + specifier: ^2.30.3 + version: 2.30.3 npm-run-all2: specifier: ^6.1.2 version: 6.1.2 @@ -179,9 +179,9 @@ importers: isomorphic-dompurify: specifier: ^2.7.0 version: 2.7.0 - moment-mini: - specifier: ^2.29.4 - version: 2.29.4 + moment-tiny: + specifier: ^2.30.3 + version: 2.30.3 multiple-select-vanilla: specifier: ^3.1.0 version: 3.1.0 @@ -249,9 +249,9 @@ importers: isomorphic-dompurify: specifier: ^2.7.0 version: 2.7.0 - moment-mini: - specifier: ^2.29.4 - version: 2.29.4 + moment-tiny: + specifier: ^2.30.3 + version: 2.30.3 multiple-select-vanilla: specifier: ^3.1.0 version: 3.1.0 @@ -310,9 +310,9 @@ importers: '@slickgrid-universal/common': specifier: workspace:~ version: link:../common - moment-mini: - specifier: ^2.29.4 - version: 2.29.4 + moment-tiny: + specifier: ^2.30.3 + version: 2.30.3 devDependencies: '@slickgrid-universal/event-pub-sub': specifier: workspace:~ @@ -357,9 +357,9 @@ importers: excel-builder-vanilla: specifier: ^3.0.1 version: 3.0.1 - moment-mini: - specifier: ^2.29.4 - version: 2.29.4 + moment-tiny: + specifier: ^2.30.3 + version: 2.30.3 devDependencies: '@slickgrid-universal/event-pub-sub': specifier: workspace:~ @@ -374,9 +374,9 @@ importers: specifier: workspace:~ version: link:../utils devDependencies: - moment-mini: - specifier: ^2.29.4 - version: 2.29.4 + moment-tiny: + specifier: ^2.30.3 + version: 2.30.3 packages/odata: dependencies: @@ -6894,8 +6894,8 @@ packages: hasBin: true dev: true - /moment-mini@2.29.4: - resolution: {integrity: sha512-uhXpYwHFeiTbY9KSgPPRoo1nt8OxNVdMVoTBYHfSEKeRkIkwGpO+gERmhuhBtzfaeOyTkykSrm2+noJBgqt3Hg==} + /moment-tiny@2.30.3: + resolution: {integrity: sha512-FgTYWVw+j63lHaUex7u1W0ix+2K5r4xEpGkLwkdIfuvl4g1v7NJgCQMHCi7BsSp3IcFdXOnCoroRUPRPlJGr5w==} /ms@2.1.2: resolution: {integrity: sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==} diff --git a/test/cypress/e2e/example02.cy.ts b/test/cypress/e2e/example02.cy.ts index ffb79a8d4..773bab389 100644 --- a/test/cypress/e2e/example02.cy.ts +++ b/test/cypress/e2e/example02.cy.ts @@ -1,4 +1,4 @@ -import moment from 'moment-mini'; +import moment from 'moment-tiny'; import { removeExtraSpaces } from '../plugins/utilities'; describe('Example 02 - Grouping & Aggregators', () => { diff --git a/test/cypress/e2e/example10.cy.ts b/test/cypress/e2e/example10.cy.ts index 110710c96..0e9dd16be 100644 --- a/test/cypress/e2e/example10.cy.ts +++ b/test/cypress/e2e/example10.cy.ts @@ -1,4 +1,4 @@ -import moment from 'moment-mini'; +import moment from 'moment-tiny'; function removeSpaces(textS) { return `${textS}`.replace(/\s+/g, ''); diff --git a/test/cypress/e2e/example11.cy.ts b/test/cypress/e2e/example11.cy.ts index 501f4cfa4..ef133f210 100644 --- a/test/cypress/e2e/example11.cy.ts +++ b/test/cypress/e2e/example11.cy.ts @@ -1,4 +1,4 @@ -import moment from 'moment-mini'; +import moment from 'moment-tiny'; import { changeTimezone, zeroPadding } from '../plugins/utilities'; describe('Example 11 - Batch Editing', () => { diff --git a/test/jest-global-mocks.ts b/test/jest-global-mocks.ts index 0692d4a7b..fc87b1809 100644 --- a/test/jest-global-mocks.ts +++ b/test/jest-global-mocks.ts @@ -39,7 +39,7 @@ Object.defineProperty(window, 'matchMedia', { }); // Jest has a hard time with MomentJS because they export as default, to bypass this problem we can mock the require .default -jest.mock('moment-mini', () => { - const actual = jest.requireActual('moment-mini'); +jest.mock('moment-tiny', () => { + const actual = jest.requireActual('moment-tiny'); return { __esModule: true, ...actual, default: actual }; }); \ No newline at end of file