Skip to content

Commit 03226c6

Browse files
authored
Merge pull request #1088 from lmetdaoui/main
fix: handle arabic short week days
2 parents 6e27d06 + 5ef0b0c commit 03226c6

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

src/VueDatePicker/utils/util.ts

+9-5
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,15 @@ export const getArrayInArray = <T>(list: T[], increment = 3): T[][] => {
2626

2727
function dayNameIntlMapper(locale: string) {
2828
return (day: number) => {
29-
return new Intl.DateTimeFormat(locale, { weekday: 'short', timeZone: 'UTC' })
30-
.format(new Date(`2017-01-0${day}T00:00:00+00:00`))
31-
.slice(0, 2);
32-
};
33-
}
29+
const formattedDate = new Intl.DateTimeFormat(locale, {
30+
weekday: 'short',
31+
timeZone: 'UTC'
32+
}).format(new Date(`2017-01-0${day}T00:00:00+00:00`));
33+
34+
// Arabic locale requires different slice indexes to get correct abbreviation
35+
return locale === 'ar' ? formattedDate.slice(2, 5) : formattedDate.slice(0, 2);
36+
}
37+
};
3438

3539
function dayNameDateFnsMapper(formatLocale: Locale) {
3640
return (day: number) => {

tests/unit/utils.spec.ts

+8
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,14 @@ describe('Utils and date utils formatting', () => {
109109
expect(days[1]).toEqual('Di');
110110
});
111111

112+
it('Should get specific day names on arabic', () => {
113+
// Pass arabic locale
114+
const days = getDayNames(null, 'ar', 1);
115+
116+
expect(days).toHaveLength(7);
117+
expect(days[1]).toEqual('ثلا');
118+
});
119+
112120
it('Should get day names according to formatLocale', () => {
113121
const days = getDayNames(de, 'en', 1);
114122

0 commit comments

Comments
 (0)