From 7b5a60a34b67bfc3762e1bd1d91274efad2df5ab Mon Sep 17 00:00:00 2001 From: Lukas Date: Mon, 5 Feb 2024 17:07:30 +0200 Subject: [PATCH 1/2] [pickers] Avoid relying on locale in Luxon `isWithinRange` method (#11936) --- .../x-date-pickers/src/AdapterLuxon/AdapterLuxon.ts | 4 ++-- .../describeGregorianAdapter/testCalculations.ts | 11 ++++++++++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/packages/x-date-pickers/src/AdapterLuxon/AdapterLuxon.ts b/packages/x-date-pickers/src/AdapterLuxon/AdapterLuxon.ts index 60cdfa0341844..1af5e9383e21b 100644 --- a/packages/x-date-pickers/src/AdapterLuxon/AdapterLuxon.ts +++ b/packages/x-date-pickers/src/AdapterLuxon/AdapterLuxon.ts @@ -368,8 +368,8 @@ export class AdapterLuxon implements MuiPickersAdapter { public isWithinRange = (value: DateTime, [start, end]: [DateTime, DateTime]) => { return ( - value.equals(start) || - value.equals(end) || + this.isEqual(value, start) || + this.isEqual(value, end) || (this.isAfter(value, start) && this.isBefore(value, end)) ); }; diff --git a/test/utils/pickers/describeGregorianAdapter/testCalculations.ts b/test/utils/pickers/describeGregorianAdapter/testCalculations.ts index 00969e3f0d85b..019d409919766 100644 --- a/test/utils/pickers/describeGregorianAdapter/testCalculations.ts +++ b/test/utils/pickers/describeGregorianAdapter/testCalculations.ts @@ -693,7 +693,7 @@ export const testCalculations: DescribeGregorianAdapterTestSuite = ({ ).to.equal(false); }); - it('should use inclusivity of range', () => { + it('should use inclusiveness of range', () => { expect( adapter.isWithinRange(adapter.date('2019-09-01T00:00:00.000Z')!, [ adapter.date('2019-09-01T00:00:00.000Z')!, @@ -722,6 +722,15 @@ export const testCalculations: DescribeGregorianAdapterTestSuite = ({ ]), ).to.equal(true); }); + + it('should be equal with values in different locales', () => { + expect( + adapter.isWithinRange(adapter.date('2022-04-17'), [ + adapterFr.date('2022-04-17'), + adapterFr.date('2022-04-19'), + ]), + ).to.equal(true); + }); }); it('Method: startOfYear', () => { From 79f0abc6c86a012110a06ff8e61336c3d42c4dc8 Mon Sep 17 00:00:00 2001 From: Lukas Date: Tue, 6 Feb 2024 10:22:20 +0200 Subject: [PATCH 2/2] Make TS happy --- .../pickers/describeGregorianAdapter/testCalculations.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/utils/pickers/describeGregorianAdapter/testCalculations.ts b/test/utils/pickers/describeGregorianAdapter/testCalculations.ts index 019d409919766..c112de5ba9f9b 100644 --- a/test/utils/pickers/describeGregorianAdapter/testCalculations.ts +++ b/test/utils/pickers/describeGregorianAdapter/testCalculations.ts @@ -725,9 +725,9 @@ export const testCalculations: DescribeGregorianAdapterTestSuite = ({ it('should be equal with values in different locales', () => { expect( - adapter.isWithinRange(adapter.date('2022-04-17'), [ - adapterFr.date('2022-04-17'), - adapterFr.date('2022-04-19'), + adapter.isWithinRange(adapter.date('2022-04-17')!, [ + adapterFr.date('2022-04-17')!, + adapterFr.date('2022-04-19')!, ]), ).to.equal(true); });