Skip to content
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
2 changes: 1 addition & 1 deletion packages/x-date-pickers/src/AdapterLuxon/AdapterLuxon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ export class AdapterLuxon implements MuiPickersAdapter<string> {
};

public getDayOfWeek = (value: DateTime) => {
return value.weekday;
return value.localWeekday ?? value.weekday;
};

public getYearRange = ([start, end]: [DateTime, DateTime]) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ export class AdapterLuxon implements Adapter<string> {
};

public getDayOfWeek = (value: DateTime) => {
return value.weekday;
return value.localWeekday ?? value.weekday;
};

public getYearRange = ([start, end]: [DateTime, DateTime]) => {
Expand Down
6 changes: 4 additions & 2 deletions packages/x-scheduler/src/primitives/utils/date-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ export function mergeDateAndTime(
}

export function isWeekend(adapter: Adapter, value: SchedulerValidDate): boolean {
const dayOfWeek = adapter.getDayOfWeek(value);
const sunday = adapter.format(adapter.date('2025-08-09'), 'weekday');
Copy link
Member Author

Choose a reason for hiding this comment

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

I'm struggling to find a better way to detect the week end 😬
I'm not even sure if some adapter have a locale-based notion of "Week end".

Copy link
Member

Choose a reason for hiding this comment

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

Neat trick! 👀

Copy link
Member

Choose a reason for hiding this comment

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

But the weekend might not be on Saturday and Sunday for every locale. 🤔
Doesn't US technically have the weekend on Sunday and Monday?

Copy link
Member

Choose a reason for hiding this comment

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

Scratch that previous question part.
Regardless, based on ChatGPT information, some countries do have weekends on different days:
Screenshot 2025-08-19 at 16 17 49

Copy link
Member Author

Choose a reason for hiding this comment

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

Doesn't US technically have the weekend on Sunday and Monday?

No, the week start on Sunday, but the week end is still Sartuday and Sunday AFAIK.
Those are two distinct concepts, sadly enough we don't use "week-end" to mean the end of the week 👨 🔫 . So for me the behavior of the Scheduler before this PR was already broken, probably even more than after the PR.

With that being said, I'm not surprised that not all country and culture have Saturday + Sunday as week end. Bryntum has a concept of working days (that user can define manually) which is probably what you want in a lot of scenarios (to include public holdays for example). But I'm not sure it's always what we want and I'm wondering if there is a disctinct concept of week end.
It seems that Bryntum uses there concept of "non working days" for the equivalent of the UI we built. BUT at the same time they have a class specific to week end that apply to Saturday and Sunday (they don't implement the nuance Chat GPT gave, or at least it's not documented).

image image

TLDR: It's a mess and I think starting with the current approach and then research how to best introduce a notion of working / non-working days is fine.

Copy link
Member

@LukasTy LukasTy Aug 19, 2025

Choose a reason for hiding this comment

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

WDYT about adding a isWeekend method to the adapter?
Looks like Luxon and date-fns have the means to resolve this, whereas for others we can use getWeekInfo as a basis and fallback to your solution if weekInfo is not available (i.e. Firefox).

Copy link
Member Author

Choose a reason for hiding this comment

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

It would probably be the right solution.
I think we can add it to the Base UI version and keep it hardcoded for now in the Scheduler while we use a copy paste of the MUI X adapters (I'd like to avoid having 3 versions of the adapter to maintain 😆 )

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, the notion of work days is probably the best shot at being the silver bullet for the Scheduler's case. 👌
I agree with your proposal. 👍

Copy link
Member Author

Choose a reason for hiding this comment

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

To summarize:

  1. Hardcode Saturday and Sunday in the Scheduler for now
  2. Add a isWeekend method on the Base UI adapters
  3. When the Scheduler starts using the Base UI adapters, remove the hardcoded days and use the method instead
  4. When we introduce a notion of working / non-working days, set the default value to equal the week end days (using isWeekEnd).

const saturday = adapter.format(adapter.date('2025-08-10'), 'weekday');
const formattedValue = adapter.format(value, 'weekday');

return dayOfWeek === 6 || dayOfWeek === 7;
return formattedValue === sunday || formattedValue === saturday;
}
Original file line number Diff line number Diff line change
Expand Up @@ -740,7 +740,7 @@ export const testCalculations: DescribeGregorianAdapterTestSuite = ({
});

it('Method: getDayOfWeek', () => {
expect(adapter.getDayOfWeek(testDateIso)).to.equal(adapter.lib === 'luxon' ? 2 : 3);
expect(adapter.getDayOfWeek(testDateIso)).to.equal(3);
});

describe('Method: getWeekArray', () => {
Expand Down