Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pickers] Draft support for js-joda #8438

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions packages/x-date-pickers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
"peerDependencies": {
"@emotion/react": "^11.9.0",
"@emotion/styled": "^11.8.1",
"@js-joda/core": "^5.6.2",
"@mui/material": "^5.15.14",
"date-fns": "^2.25.0 || ^3.2.0",
"date-fns-jalali": "^2.13.0-0",
Expand All @@ -75,6 +76,9 @@
"@emotion/styled": {
"optional": true
},
"@js-joda/core": {
"optional": true
},
"date-fns": {
"optional": true
},
Expand All @@ -98,6 +102,7 @@
}
},
"devDependencies": {
"@js-joda/locale_en-us": "^4.11.0",
"@types/luxon": "^3.4.2",
"@types/moment-hijri": "^2.1.4",
"@types/moment-jalaali": "^0.7.9",
Expand Down
45 changes: 45 additions & 0 deletions packages/x-date-pickers/src/AdapterJsJoda/AdapterJsJoda.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { LocalDateTime, ZonedDateTime } from '@js-joda/core';
import { Locale } from '@js-joda/locale_en-us';
import { expect } from 'chai';
import { AdapterJsJoda } from './AdapterJsJoda';

const testDateString = '2024-04-27T11:44:00.000';
const testSundayString = '2024-04-21T11:44:00.000';

describe('<AdapterJsJoda/>', () => {
const adapter = new AdapterJsJoda({ locale: Locale.ENGLISH });

it('allows comparisons between zoned and local timestamps', () => {
// MUI-X and clients may not consistently specify timezones. We don't want
// to make them accommodate js-joda's stricter behavior here.
const t1 = LocalDateTime.parse(testDateString);
const t2 = ZonedDateTime.parse(`${testDateString}Z`);
expect(adapter.isEqual(t1, t2)).to.equal(true);
expect(adapter.isBefore(t1, t2.plusMinutes(1))).to.equal(true);
expect(adapter.isBefore(t1, t2.minusMinutes(1))).to.equal(false);
expect(adapter.isAfter(t1, t2.plusMinutes(1))).to.equal(false);
expect(adapter.isAfter(t1, t2.minusMinutes(1))).to.equal(true);
});

it('gets the start of a week', () => {
let date = adapter.date(testDateString);
let startOfWeek = adapter.startOfWeek(date);
expect(startOfWeek.toJSON()).to.equal('2024-04-21T00:00');

date = adapter.date(testSundayString);
startOfWeek = adapter.startOfWeek(date);
expect(startOfWeek.toJSON()).to.equal('2024-04-21T00:00');
});

it('gets the week number', () => {
const date = adapter.date(testDateString);
const startOfWeek = adapter.startOfWeek(date);
expect(adapter.getWeekNumber(date)).to.equal(17);
expect(adapter.getWeekNumber(startOfWeek)).to.equal(17);
});

it('gets the day of the week', () => {
const date = adapter.date(testDateString);
expect(adapter.getDayOfWeek(date)).to.equal(7);
});
});
Loading