Skip to content

Commit

Permalink
fix: add back moment rollup patch with default import
Browse files Browse the repository at this point in the history
- seems like this was causing issues while trying to implement this in Aurelia-Slickgrid with WebPack which tried to load invalid import with default
  • Loading branch information
ghiscoding committed Dec 16, 2023
1 parent 6bddb4e commit 2e81421
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 9 deletions.
3 changes: 2 additions & 1 deletion packages/common/src/editors/dateEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import { createDomElement, destroyAllElementProps, emptyElement, setDeepValue }
import flatpickr from 'flatpickr';
import type { BaseOptions as FlatpickrBaseOptions } from 'flatpickr/dist/types/options';
import type { Instance as FlatpickrInstance } from 'flatpickr/dist/types/instance';
import moment from 'moment-mini';
import * as moment_ from 'moment-mini';
const moment = (moment_ as any)['default'] || moment_;

import { Constants } from './../constants';
import { FieldType } from '../enums/index';
Expand Down
4 changes: 3 additions & 1 deletion packages/common/src/filters/dateFilter.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { BindingEventService } from '@slickgrid-universal/binding';
import { createDomElement, destroyAllElementProps, emptyElement, } from '@slickgrid-universal/utils';
import flatpickr from 'flatpickr';
import moment from 'moment-mini';
import * as moment_ from 'moment-mini';
const moment = (moment_ as any)['default'] || moment_;

import type { BaseOptions as FlatpickrBaseOptions } from 'flatpickr/dist/types/options';
import type { Instance as FlatpickrInstance } from 'flatpickr/dist/types/instance';

Expand Down
3 changes: 2 additions & 1 deletion packages/common/src/services/utilities.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { EventSubscription } from '@slickgrid-universal/event-pub-sub';
import { flatten } from 'un-flatten-tree';
import moment from 'moment-mini';
import * as moment_ from 'moment-mini';
const moment = (moment_ as any)['default'] || moment_;

import { Constants } from '../constants';
import { FieldType, type OperatorString, OperatorType } from '../enums/index';
Expand Down
13 changes: 7 additions & 6 deletions packages/common/src/sortComparers/dateUtilities.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
import moment from 'moment-mini';
import * as moment_ from 'moment-mini';
const moment = (moment_ as any)['default'] || moment_;

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 | moment_.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_.Moment | Date = moment(value1, format, strict);
let date2: moment_.Moment | Date = moment(value2, format, strict);

// when moment date is invalid, we'll create a temporary old Date
if (!date1.isValid()) {
if (!(date1 as moment_.Moment).isValid()) {
date1 = new Date(1001, 1, 1);
}
if (!date2.isValid()) {
if (!(date2 as moment_.Moment).isValid()) {
date2 = new Date(1001, 1, 1);
}

Expand Down

0 comments on commit 2e81421

Please sign in to comment.