Components: feat(datepicker): add setting to define the first day of a week

Created on 20 Sep 2017  路  4Comments  路  Source: angular/components

Bug, feature request, or proposal:

Feature request

What is the expected behavior?

The developer should be able to set the first day of a week in a datepicker.

What is the current behavior?

The first day of the week is always sunday.

What is the use-case or motivation for changing an existing behavior?

In north america it is common that a week starts with sunday, but for example in germany (and i guess most european countries) the first day of the week is usually considered monday.

Which versions of Angular, Material, OS, TypeScript, browsers are affected?

Angular Material 2.0.0-beta.10

Is there anything else we should know?

First day of the week in ISO 8601 is also defined to be monday.

Most helpful comment

You can do it by creating your custom date adapter. If there's no special needs, just extends the Material NativeDateAdapter and overide the getFirstDayOfWeek() function. It must return the number of the first day of the week (0 - Sunday, 1 - Monday etc).

Here is a plunk, setting Tuesday as the first day of the week: https://plnkr.co/edit/9hEJki?p=preview

getFirstDayOfWeek(): number {
   return 2;
}

All 4 comments

You can do it by creating your custom date adapter. If there's no special needs, just extends the Material NativeDateAdapter and overide the getFirstDayOfWeek() function. It must return the number of the first day of the week (0 - Sunday, 1 - Monday etc).

Here is a plunk, setting Tuesday as the first day of the week: https://plnkr.co/edit/9hEJki?p=preview

getFirstDayOfWeek(): number {
   return 2;
}

Thank you, i didn't expected it to be part of the date adapter so i didn't searched there.

Currently in the NativeDateAdapter implementation it defaults to 0 because it can't be defined using native JS dates:

getFirstDayOfWeek(): number {
  // We can't tell using native JS Date what the first day of the week is, we default to Sunday.
  return 0;
}

I think setting the first day of a week is part of i18n. So maybe there could be a property for that on the MdDatepickerIntl service?

Closing, working as intended to use the DateAdapter as mentioned

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

_This action has been performed automatically by a bot._

Was this page helpful?
0 / 5 - 0 ratings

Related issues

vitaly-t picture vitaly-t  路  3Comments

LoganDupont picture LoganDupont  路  3Comments

shlomiassaf picture shlomiassaf  路  3Comments

theunreal picture theunreal  路  3Comments

dzrust picture dzrust  路  3Comments