From ac967924c11cb40325a9fa9e2721330a948f9355 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Tue, 6 Feb 2024 10:38:50 +0200 Subject: [PATCH] [pickers] Avoid relying on locale in Luxon `isWithinRange` method (@LukasTy) (#11940) Co-authored-by: Lukas --- .../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 60cdfa034184..1af5e9383e21 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 00969e3f0d85..c112de5ba9f9 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', () => {