Skip to content

fix: handle arabic short week days #1088

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

Merged
merged 1 commit into from
Mar 15, 2025
Merged
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
14 changes: 9 additions & 5 deletions src/VueDatePicker/utils/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,15 @@ export const getArrayInArray = <T>(list: T[], increment = 3): T[][] => {

function dayNameIntlMapper(locale: string) {
return (day: number) => {
return new Intl.DateTimeFormat(locale, { weekday: 'short', timeZone: 'UTC' })
.format(new Date(`2017-01-0${day}T00:00:00+00:00`))
.slice(0, 2);
};
}
const formattedDate = new Intl.DateTimeFormat(locale, {
weekday: 'short',
timeZone: 'UTC'
}).format(new Date(`2017-01-0${day}T00:00:00+00:00`));

// Arabic locale requires different slice indexes to get correct abbreviation
return locale === 'ar' ? formattedDate.slice(2, 5) : formattedDate.slice(0, 2);
}
};

function dayNameDateFnsMapper(formatLocale: Locale) {
return (day: number) => {
Expand Down
8 changes: 8 additions & 0 deletions tests/unit/utils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,14 @@ describe('Utils and date utils formatting', () => {
expect(days[1]).toEqual('Di');
});

it('Should get specific day names on arabic', () => {
// Pass arabic locale
const days = getDayNames(null, 'ar', 1);

expect(days).toHaveLength(7);
expect(days[1]).toEqual('ثلا');
});

it('Should get day names according to formatLocale', () => {
const days = getDayNames(de, 'en', 1);

Expand Down