Skip to content

Commit

Permalink
fix: fix getWeekDays function (#1040)
Browse files Browse the repository at this point in the history
  • Loading branch information
xSyki authored Oct 3, 2023
1 parent 9e5a4a0 commit 8822223
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/components/Datepicker/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,13 @@ export enum Views {
}

export enum WeekStart {
Saturday = 0,
Saturday,
Sunday,
Monday,
Tuesday,
Wednesday,
Thursday,
Friday,
}

export const isDateInRange = (date: Date, minDate?: Date, maxDate?: Date): boolean => {
Expand Down Expand Up @@ -61,14 +65,13 @@ export const getFirstDayOfTheMonth = (date: Date, weekStart: WeekStart): Date =>

export const getWeekDays = (lang: string, weekStart: WeekStart): string[] => {
const weekdays: string[] = [];
const date = new Date();
const date = new Date(0);

const formatter = new Intl.DateTimeFormat(lang, { weekday: 'short' });

for (let i = 0; i < 7; i++) {
const dayIndex = (i + weekStart + 1) % 7; // Calculate the correct day index based on weekStart
date.setDate(dayIndex + 1);
const formattedWeekday = formatter.format(date);
const dayIndex = (i + weekStart + 1) % 7;
const formattedWeekday = formatter.format(addDays(date, dayIndex + 1));
weekdays.push(formattedWeekday.slice(0, 2).charAt(0).toUpperCase() + formattedWeekday.slice(1, 3));
}

Expand Down

1 comment on commit 8822223

@vercel
Copy link

@vercel vercel bot commented on 8822223 Oct 3, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.