forked from mui/mui-x
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[pickers] Add
AdapterDateFnsJalaliV3
adapter (mui#12891)
Co-authored-by: Lukas <[email protected]>
- Loading branch information
1 parent
dbc81d3
commit 545e079
Showing
16 changed files
with
692 additions
and
1,849 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -91,9 +91,20 @@ module.exports = function getBabelConfig(api) { | |
{ | ||
test: /date-fns/i, | ||
replacer: 'date-fns-v3', | ||
ignoreFilenames: 'AdapterDateFns.ts', | ||
// This option is provided by the `patches/[email protected]` patch | ||
filenameIncludes: 'src/AdapterDateFnsV3/', | ||
}, | ||
]); | ||
plugins.push([ | ||
'babel-plugin-replace-imports', | ||
{ | ||
test: /date-fns-jalali/i, | ||
replacer: 'date-fns-jalali-v3', | ||
// This option is provided by the `patches/[email protected]` patch | ||
filenameIncludes: 'src/AdapterDateFnsJalaliV3/', | ||
}, | ||
'replace-date-fns-jalali-imports', | ||
]); | ||
} | ||
|
||
if (process.env.NODE_ENV === 'production') { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -129,6 +129,7 @@ | |
"cpy-cli": "^5.0.0", | ||
"cross-env": "^7.0.3", | ||
"danger": "^11.3.1", | ||
"date-fns-jalali-v3": "npm:[email protected]", | ||
"date-fns-v3": "npm:[email protected]", | ||
"enzyme": "^3.11.0", | ||
"eslint": "^8.57.0", | ||
|
@@ -195,7 +196,6 @@ | |
"packageManager": "[email protected]", | ||
"pnpm": { | ||
"patchedDependencies": { | ||
"[email protected]": "patches/[email protected]", | ||
"[email protected]": "patches/[email protected]", | ||
"[email protected]": "patches/[email protected]" | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
packages/x-date-pickers-pro/src/AdapterDateFnsJalaliV3/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { AdapterDateFnsJalali } from '@mui/x-date-pickers/AdapterDateFnsJalaliV3'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
packages/x-date-pickers/src/AdapterDateFnsJalaliV3/AdapterDateFnsJalaliV3.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
import { expect } from 'chai'; | ||
import { DateTimeField } from '@mui/x-date-pickers'; | ||
import { AdapterDateFnsJalali } from '@mui/x-date-pickers/AdapterDateFnsJalaliV3'; | ||
import { | ||
createPickerRenderer, | ||
expectFieldValueV7, | ||
describeJalaliAdapter, | ||
buildFieldInteractions, | ||
} from 'test/utils/pickers'; | ||
import { enUS, faIR } from 'date-fns-jalali/locale'; | ||
import { AdapterFormats } from '@mui/x-date-pickers/models'; | ||
|
||
describe('<AdapterDateFnsJalaliV3 />', () => { | ||
describeJalaliAdapter(AdapterDateFnsJalali, {}); | ||
|
||
describe('Adapter localization', () => { | ||
it('Formatting', () => { | ||
const adapter = new AdapterDateFnsJalali(); | ||
|
||
const expectDate = (format: keyof AdapterFormats, expectedWithFaIR: string) => { | ||
const date = adapter.date('2020-02-01T23:44:00.000Z')!; | ||
|
||
expect(adapter.format(date, format)).to.equal(expectedWithFaIR); | ||
}; | ||
|
||
expectDate('fullDate', '12-ام بهمن 1398'); | ||
expectDate('keyboardDate', '1398/11/12'); | ||
expectDate('keyboardDateTime', '1398/11/12 11:44 ب.ظ.'); | ||
expectDate('keyboardDateTime12h', '1398/11/12 11:44 ب.ظ.'); | ||
expectDate('keyboardDateTime24h', '1398/11/12 23:44'); | ||
}); | ||
}); | ||
|
||
describe('Picker localization', () => { | ||
const testDate = '2018-05-15T09:35:00'; | ||
const localizedTexts = { | ||
enUS: { | ||
placeholder: 'MM/DD/YYYY hh:mm aa', | ||
value: '02/25/1397 09:35 AM', | ||
}, | ||
faIR: { | ||
placeholder: 'YYYY/MM/DD hh:mm aa', | ||
value: '1397/02/25 09:35 ق.ظ.', | ||
}, | ||
}; | ||
|
||
Object.keys(localizedTexts).forEach((localeKey) => { | ||
const localeObject = { | ||
faIR, | ||
enUS, | ||
}[localeKey]; | ||
|
||
describe(`test with the "${localeKey}" locale`, () => { | ||
const { render, adapter, clock } = createPickerRenderer({ | ||
clock: 'fake', | ||
adapterName: 'date-fns-jalali', | ||
locale: localeObject, | ||
}); | ||
|
||
const { renderWithProps } = buildFieldInteractions({ | ||
render, | ||
clock, | ||
Component: DateTimeField, | ||
}); | ||
|
||
it('should have correct placeholder', () => { | ||
const v7Response = renderWithProps({ enableAccessibleFieldDOMStructure: true }); | ||
|
||
expectFieldValueV7( | ||
v7Response.getSectionsContainer(), | ||
localizedTexts[localeKey].placeholder, | ||
); | ||
}); | ||
|
||
it('should have well formatted value', () => { | ||
const v7Response = renderWithProps({ | ||
enableAccessibleFieldDOMStructure: true, | ||
value: adapter.date(testDate), | ||
}); | ||
|
||
expectFieldValueV7(v7Response.getSectionsContainer(), localizedTexts[localeKey].value); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.